Answer the question
In order to leave comments, you need to log in
How to process a list of inputs?
Hello everyone, I have an array of objects, inside the objects there is another array of objects, based on this array I display a list of inputs. Now how can I make event handlers for each input in order to send them to the back in the same form as they arrived to me, only with new values
const renderAllConditionsProperties = () => {
return conditions && conditions.map((a: any) => {
return a.conditionProperties.map((item: any) => {
return (
<div>
<span>{item.propertyDescription}: </span>
<Input
style={{
border: '1px solid #0079E9',
width: '10%',
boxSizing: 'border-box',
height: '33px',
borderRadius: '10px',
marginTop: '50px'
}}
key={item.conditionProperyId}
value={item.propertyValue}
// onChange={(e) => setTest((prevState) => prevState.find((c) => c[propertyName] === item.propertyName))}
/>
</div>
)
})
})
}
Answer the question
In order to leave comments, you need to log in
You can use the Immer library
example
!!!it's very bad to do this, but the order is important to you, so you can't normalize
onChange={(e) =>
setTest(
produce((draft) => {
draft.conditions.forEach((c) =>
c.conditionProperties.forEach((prop) => {
if (prop.propertyName === item.propertyName) {
prop.propertyValue = e.target.value;
}
})
);
})
)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question