Skip to content
Advertisement

React : Cannot set property ‘animation’ of undefined

I have a list in React where I’m using .map to render a loop from an array of elements.

The radio inputs are working perfectly, everyone is independent of the others, but I can’t do the same for Select.

The Select area is changing in every field, I want it to change to it specified field like I did for the options.

I tried to re-use the same handleChange that I used in the radios for it and instead I had this error.

JavaScript

In this line

JavaScript

How do I manage to separate the selects ? Note: This code is working fine, but it’s updating the value on every field.

JavaScript

Code : https://codesandbox.io/s/dank-violet-jibzh?file=/src/App.js:1065-1194

JavaScript

Advertisement

Answer

Multiple Selects share the same state, resulting in updates the value on every field. So we need to wrap Select into components and maintain their own state independently:

JavaScript
JavaScript

Update

Modify the links when select is selected:

JavaScript
JavaScript

Full code: https://codesandbox.io/s/happy-cloud-m6z99?file=/src/App.js:77-298

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement