From d7dbd63c923a63957552e1c79d969b4d21a9f1de Mon Sep 17 00:00:00 2001 From: Akshay Vishwanath Bhosale Date: Tue, 9 Aug 2022 20:27:25 +0530 Subject: [PATCH 1/2] useEffect Hooks --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index dfb8bfaa..12733370 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,5 @@ All course files for the Complete React Tutorial on the Net Ninja YouTube channel. To use, select the correct branch for each Lesson. E.g for lesson 5 code, select the lesson-5 branch from the drop-down. + +useEffect From 14ed7964777b636a46b7f221c1ccfdceb244e25c Mon Sep 17 00:00:00 2001 From: Akshay Vishwanath Bhosale Date: Tue, 9 Aug 2022 20:34:26 +0530 Subject: [PATCH 2/2] Update README.md --- README.md | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 12733370..f6fc1129 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,41 @@ All course files for the Complete React Tutorial on the Net Ninja YouTube channe To use, select the correct branch for each Lesson. E.g for lesson 5 code, select the lesson-5 branch from the drop-down. -useEffect +useEffect Hooks: + +useEffect: Run after every render. +e.g.: useEffect(() =>{ + console.log('use effect run'); + }) + +useEffect Dependancy: create empty array + +e.g.: useEffect(() =>{ + console.log('use effect run'); + },[]); + +then this function run only after initial render and when state changes. here no actual +dependencies in array. + +Now add actual dependncies in array: + +When name changes automatically render this name. like watch the name + +const Home = () => { + + const [name, setName] = useState('initial name'); + + useEffect(() => { + console.log('use effect ran'); + + }, [name]) + + return ( +
+ + +
+ ); +} + +