Skip to content

Instantly share code, notes, and snippets.

@arvi9
Created July 27, 2020 17:31
Show Gist options
  • Save arvi9/c7ffecb8e960e212caffe11492965798 to your computer and use it in GitHub Desktop.
Save arvi9/c7ffecb8e960e212caffe11492965798 to your computer and use it in GitHub Desktop.
React useEffect Demo
<div id="root">
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'));
<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>
@arvi9
Copy link
Author

arvi9 commented Jul 27, 2020

React useEffect Demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment