Last active
May 5, 2020 16:55
-
-
Save showlovezz/c1adf6227a839d516c4474f933ad5f15 to your computer and use it in GitHub Desktop.
鼠年全馬鐵人挑戰 - React Hooks useEffect 7
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', | |
}, | |
}, | |
] | |
// 這樣子會變成,每次按下 button 時,console.log(userData) 就會每次執行,如果要改成只要初始渲染的話,加個空 [] 即可。 | |
useEffect(() => { | |
console.log(userData); | |
}) | |
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