From 042c85c1fe38e4f2ea9caf893c75610265e08382 Mon Sep 17 00:00:00 2001 From: Mathias Date: Wed, 3 Mar 2021 20:16:54 +0100 Subject: [PATCH] Change example --- react-examples.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/react-examples.md b/react-examples.md index 152e133..3aa7a5d 100644 --- a/react-examples.md +++ b/react-examples.md @@ -6,7 +6,9 @@ //MyComponent.js import React from "react"; -const MyComponent = ({ title, content }) => { +// const MyComponent = ({ title, content }) => {... +const MyComponent = (props) => { + const { title, content } = props; return (

{title}

@@ -63,6 +65,31 @@ const ComponentWithState = () => { export default ComponentWithState; ``` +## useEffect + +```javascript +import React, { useEffect } from "react"; + +const UseEffectComponent = () => { + const [count, setCount] = useState(0); + + useEffect(() => { + // Update the document title using the browser API + document.title = `You clicked ${count} times`; + }, []); + + return ( +
+

You clicked {count} times

+ +
+}; + +export default ComponentWithState; +``` + ## User events ```javascript