📜  javascript react useState 更新对象 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:20.735000             🧑  作者: 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'
         }));