引入
js
import { useState } from "react";
定义
js
const [count, setCount] = useState(0);
使用
js
import { useState } from "react";
function Son(params) {
const [count, setCount] = useState(0);
function handleClick() {
setCount(count + 1);
}
// 父 <Son count={count}></Son>
console.log(params, 'paramsparams');
return (
<div>
{params.count}
<button onClick={handleClick}>
Clicked {count} Son times
</button>
</div>
)
}
export default Son;