2

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 });
    };

2
  • "how can I change it?" ... change it how? What are you trying to accomplish? Commented Apr 6, 2021 at 1:36
  • @Lili How does the result array look like ? Commented Apr 7, 2021 at 11:07

1 Answer 1

1

Try this:

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

const handleInputChange = event => {
        console.log(event.target.value)
        setCurrentStates({ ...currentStates, [name]: event.target.value});
   };
Sign up to request clarification or add additional context in comments.

2 Comments

Can’t work🥲it make me a error with the [name]
You need to check your value inside the form

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.