Last active
September 6, 2020 14:42
-
-
Save codegagan/984dd100bedffb069a4d120ef3e1ffaf to your computer and use it in GitHub Desktop.
Test with multiple useState implementations
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, { useState } from "react"; | |
export default function MultipleStatesComponent() { | |
const [dataLength, setDataLength] = useState(0); | |
const [loading, setLoading] = useState(false); | |
const [text, setText] = useState(""); | |
const handleButtonOne = () => { | |
setDataLength(10); | |
}; | |
const handleButtonTwo = () => { | |
setLoading(true); | |
setText("text set by button"); | |
}; | |
return ( | |
<div> | |
<h1>Set states with buttons</h1> | |
<button onClick={handleButtonOne}> Set length </button> | |
<button onClick={handleButtonTwo}> Click to set values </button> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment