Last active
May 5, 2020 16:37
-
-
Save showlovezz/972f57f9ffc6492c8a0f36300d062842 to your computer and use it in GitHub Desktop.
鼠年全馬鐵人挑戰 - React Hooks useEffect 4
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
const App = () => { | |
const [user, setUser] = useState(null) | |
useEffect(() => { | |
// 初始化,獲取數據,僅會執行一次 | |
setUser(userData) | |
}, []) | |
useEffect(() => { | |
// 更新數據 | |
}) | |
return ( | |
<div> | |
<p>{user && user.name}</p> | |
<button onClick={() => setUser()}>click</button> | |
</div> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment