This file contains 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, {useEffect, useState} from "react"; | |
const ExampleUseEffect = props => { | |
const [exampleState, setExampleState] = useState({name: "Berk"}) | |
useEffect(() => { | |
console.log("I execute in component's first render.") | |
}, []); | |
useEffect(() => { |
This file contains 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..."})); | |
} |