You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
587 B
30 lines
587 B
import { useEffect, useState } from 'react'
|
|
|
|
function Test () {
|
|
useEffect(() => {
|
|
let timer = setInterval(() => {
|
|
console.log('定时器执行了')
|
|
}, 1000)
|
|
|
|
return () => {
|
|
// 清理定时器
|
|
clearInterval(timer)
|
|
}
|
|
}, [])
|
|
|
|
return (
|
|
<div>this is test</div>
|
|
)
|
|
}
|
|
|
|
function App () {
|
|
const [flag, setFlag] = useState(true)
|
|
return (
|
|
<div>
|
|
{flag ? <Test /> : null}
|
|
<button onClick={() => setFlag(!flag)}>switch</button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default App
|