Created
July 25, 2020 17:34
-
-
Save berkelmas/2738f64ee1885ed65fdeff78d1c372d3 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 React, {useState} from "react"; | |
const ExampleComponent = props => { | |
const [exampleState, setExampleState] = useState({name: "Berk"}); | |
const changeName = () => { | |
// setExampleState will provide us with changing state; | |
// setExampleState will also provide previous state if we want to use it. | |
setExampleState(prev => ({name: "Changed..."})); | |
} | |
return ( | |
<> | |
{/* exampleState will give us {name: "Berk"} */ | |
<div>{exampleState.name}</div> | |
<button onClick={changeName}>Change Name</button> | |
</> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment