react hook函数式组件useState使用/params父向子传参

引入

import { useState } from "react";

定义

const [count, setCount] = useState(0);

使用

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

你可能感兴趣的:(react,react.js,javascript,前端)