Created
July 27, 2020 17:31
-
-
Save arvi9/c7ffecb8e960e212caffe11492965798 to your computer and use it in GitHub Desktop.
React useEffect Demo
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
<div id="root"> |
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
const App = () =>{ | |
const [count, setCount] = React.useState(0); | |
// Similar to componentDidMount and componentDidUpdate: | |
React.useEffect(() => { | |
// Update the document title using the browser API | |
document.title = `You clicked ${count} times`; | |
console.log(`You clicked ${count} times`); | |
}); | |
return <div> | |
<p>You clicked {count} times</p> | |
<button onClick={() => setCount(count + 1)}> | |
Click me | |
</button> | |
</div> | |
}; | |
ReactDOM.render(<App/>, document.querySelector('#root')); |
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
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.13.1/umd/react.production.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.13.1/umd/react-dom.production.min.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
React useEffect Demo