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.
|
|
import { useState } from 'react'
/* useState 注意事项 : 1.只能出现在函数组件中 2.不能嵌套在if/for/其它函数中(react按照hooks的调用顺序识别每一个hook) */
function App () { const [count, setCount] = useState(0) // 0 是 count 的初始值
const [flag, setFlag] = useState(true) // true 是 flag 的初始值
const [list, setList] = useState([]) // [] 是 list 的初始值,是一个空数组
function test () { setCount(count + 1) setFlag(false) setList([1, 2, 3]) }
return ( <div> count: {count} <br/> flag: {flag ? '1' : '0'} <br/> list: {list.join('-')} <button onClick={test}>+</button> </div> ) }
export default App
|