Created
May 5, 2020 17:08
-
-
Save showlovezz/b489eaa41e4747eb612bd5f7200769bf to your computer and use it in GitHub Desktop.
鼠年全馬鐵人挑戰 - React Hooks useEffect 8
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
import React, { useState, useEffect } from 'react' | |
export default () => { | |
const [count, setCount] = useState(0) | |
const userData = [ | |
{ | |
code: 200, | |
message: 'Success', | |
user: { | |
id: 1234, | |
name: 'vita', | |
age: 33, | |
gender: 'boy', | |
}, | |
}, | |
] | |
useEffect(() => { | |
console.log(userData) | |
return () => { | |
// 手動清理 effect | |
// 做一些清理的工作,在該元件卸載的時候執行 | |
} | |
}) | |
return ( | |
<section> | |
<h1>Hooks0 useState</h1> | |
<p>You clicked {count} times</p> | |
<button onClick={() => setCount(count + 1)}> | |
Click me | |
</button> | |
</section> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment