Created
July 19, 2020 23:14
-
-
Save reireynoso/4de0bb98bbfbe4e8526b08ed0e1ba109 to your computer and use it in GitHub Desktop.
Sample component restructured for forwardingRef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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