📌  相关文章
📜  更新反应钩子中的对象 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:59.783000             🧑  作者: Mango

代码示例1
- Through Input

        const [state, setState] = useState({ fName: "", lName: "" });
        const handleChange = e => {
            const { name, value } = e.target;
            setState(prevState => ({
                ...prevState,
                [name]: value
            }));
        };

        
        
   ***************************

 - Through onSubmit or button click
    
        setState(prevState => ({
            ...prevState,
            fName: 'your updated value here'
         }));