const MultipleStateVars = () => { const [age, setAge] = useState(19) const [siblingsNum, setSiblingsNum] = useState(10) const handleAge = () => setAge(age + 1) const handleSiblingsNum = () => setSiblingsNum(siblingsNum + 1) return ( <div> <p>Today I am {age} Years of Age</p> <p>I have {siblingsNum} siblings</p> <div> <button onClick={handleAge}> Get older! </button> <button onClick={handleSiblingsNum}> More siblings! </button> </div> </div> ) }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter