Skip to content

Instantly share code, notes, and snippets.

@reireynoso
Created July 19, 2020 23:14
Show Gist options
  • Save reireynoso/4de0bb98bbfbe4e8526b08ed0e1ba109 to your computer and use it in GitHub Desktop.
Save reireynoso/4de0bb98bbfbe4e8526b08ed0e1ba109 to your computer and use it in GitHub Desktop.
Sample component restructured for forwardingRef
import React, { useRef } from "react";
import AnotherComponent from './AnotherComponent'
const SampleComponent = () => {
const textInputRef = useRef(null);
const buttonClick = () => textInputRef.current.focus();
return (
<React.Fragment>
<AnotherComponent ref={textInputRef} />
<button onClick={buttonClick}>Focus on the text</button>
<React.Fragment/>
);
}
export default SampleComponent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment