Skip to content

Instantly share code, notes, and snippets.

@showlovezz
Last active May 5, 2020 16:37
Show Gist options
  • Save showlovezz/972f57f9ffc6492c8a0f36300d062842 to your computer and use it in GitHub Desktop.
Save showlovezz/972f57f9ffc6492c8a0f36300d062842 to your computer and use it in GitHub Desktop.
鼠年全馬鐵人挑戰 - React Hooks useEffect 4
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