How Can I create a Handle an input object with React hooks

Viewed 272

I have problem in my input object how can I change the onChage function this is my input code



<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>


The function “onChange” how can I change it?


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

1 Answers

Try this:

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

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