Skip to content

Instantly share code, notes, and snippets.

@showlovezz
Created May 5, 2020 17:08
Show Gist options
  • Save showlovezz/b489eaa41e4747eb612bd5f7200769bf to your computer and use it in GitHub Desktop.
Save showlovezz/b489eaa41e4747eb612bd5f7200769bf to your computer and use it in GitHub Desktop.
鼠年全馬鐵人挑戰 - React Hooks useEffect 8
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