Skip to content

Instantly share code, notes, and snippets.

@tanner-west
Last active April 21, 2022 20:49
Show Gist options
  • Save tanner-west/83616dd5028f35579b9c93115c682547 to your computer and use it in GitHub Desktop.
Save tanner-west/83616dd5028f35579b9c93115c682547 to your computer and use it in GitHub Desktop.
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