I am working on creating dynamic elements, when User clicks on add I am creating another set of elements.
once I am creating the elements I have one select option there so on selection of particular options I am creating one more field.
I have first name and select age two elements, there I have age as >18 and <=18 so on this basis I am creating one more field.
Here when I am creating one more field I am facing issue.
What I am doing
I am looping my elements
then for new element which I going to be created on selection I am doing conditional rendering
{onChangeAge && indexVal === index && (
So What I am doing is when onChange of select I am checking the value if it is >18 then setting state to that value and showing the new input field,
- But it is not working as expected, When I am selecting
>18in first set of element and selecting<=18in second then it is again setting as false. - That is due to
indexVal === indexI don't know how to handle that
Issue
The issue is when I am selecting age <=18 the I am showing one input field, the I created one more element set and there if I am again selecting <=18 then the Input field I have created in first component is not showing up.
This is my code sandbox link In my code sand box I have working code, please do check
onChangehandler ofselectelement, you are not updating the age of that input. Here's the demo of couple of changes you need to make in your code to fix the problem.