Last active
July 17, 2020 18:34
-
-
Save apackin/49ae173cfcc3ef9035bb62c53e03a941 to your computer and use it in GitHub Desktop.
App using forwardRef for FancyTextSubmit
This file contains 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
function App() { | |
const [text, setText] = useState("Fun"); | |
const fancyTextRef = useRef(); | |
const submitButton = () => { | |
setText(fancyTextRef.current.value); | |
}; | |
return ( | |
<div id="App"> | |
<p>Submitted Text is {text}</p> | |
<FancyTextSubmit ref={fancyTextRef} onClick={submitButton} /> | |
</div> | |
); | |
} | |
const FancyTextSubmit = forwardRef(({ onClick }, ref) => ( | |
<div> | |
<input ref={ref} type="text" /> | |
<button onClick={onClick}>Submit</button> | |
</div> | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment