如何使用 React hooks 创建一个处理输入对象

2024-01-07

我的输入对象有问题,如何更改 onChange 函数,这是我的输入代码



<Form.Group as={Col} controlId="formGridResultat">
                                                            <Form.Label>Result</Form.Label>
                                                            <Form.Control required as="select"
                                                                type="text"
                                                                id="conduexam.id"
                                                                name="conduexam.id"
                                                                value={currentStates. conduexam?.nom}
                                                                className={"bg-white text-dark"}
                                                                onChange={handleInputChange}>

                                                                <option value="">Choisir un Resultat </option>
                                                                {result.map((value) => (
                                                                    <option value={value.id} key={value.id}>
                                                                        {value.nom}
                                                                    </option>
                                                                ))}

                                                            </Form.Control>

                                                        </Form.Group>


“onChange”函数如何更改?


const handleInputChange = event => {
        const { name, value } = event.target;
        setCurrentStates({ ...currentStates, [name]: value });
    };


尝试这个:

const [currentStates, setCurrentStates]= useState({
//your initial code here
})

const handleInputChange = event => {
        console.log(event.target.value)
        setCurrentStates({ ...currentStates, [name]: event.target.value});
   };
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何使用 React hooks 创建一个处理输入对象 的相关文章

随机推荐