Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Component lifecycle useEffect example and exercise implementation
- Loading branch information
1 parent
370116d
commit 883b433
Showing
6 changed files
with
33 additions
and
80 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
import { ClassComponent } from "./ClassComponent" | ||
import { FunctionComponent } from "./FunctionComponent" | ||
import { Child } from "./Child" | ||
|
||
function App() { | ||
return <FunctionComponent /> | ||
//return <ClassComponent /> | ||
return <Child /> | ||
} | ||
|
||
export default App |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useEffect, useState } from "react" | ||
|
||
export function Child() { | ||
const [name, setName] = useState("") | ||
const [age, setAge] = useState(0) | ||
|
||
//useEffect example | ||
/* useEffect(() => { | ||
console.log("Name or age was changed", name, age) | ||
}, [name, age]) */ | ||
|
||
//useEffect Exercise | ||
useEffect(() => { | ||
console.log("Age has changed", age) | ||
}, [age]) | ||
|
||
return ( | ||
<div> | ||
<input value={name} onChange={(e) => setName(e.target.value)} /> | ||
<br /> | ||
<br /> | ||
<button onClick={() => setAge((currentAge) => currentAge - 1)}>-</button> | ||
{age} | ||
<button onClick={() => setAge((currentAge) => currentAge + 1)}>+</button> | ||
<p> | ||
My name is {name} and I am {age} years old | ||
</p> | ||
</div> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
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