Last active
April 21, 2022 20:49
-
-
Save tanner-west/83616dd5028f35579b9c93115c682547 to your computer and use it in GitHub Desktop.
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 { useRef, useState } from "react" | |
export default function RefComponent() { | |
const counterRef = useRef(0) | |
const [text, setText] = useState() | |
return ( | |
<div> | |
<p>counterRef: {counterRef.current}</p> | |
<p>text: {text}</p> | |
<button onClick={() => counterRef.current++}>Increment</button> | |
<br /> | |
<button onClick={() => console.log(counterRef.current)}>Log counterRef value</button> | |
<br /> | |
<input onChange={(e) => setText(e.target.value)} type="text"></input> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment