set state dynamically

function changeInput (event, property) { if (event.target.value) { setInput(prevInput => { return {...prevInput, [property]: [...prevInput.[property], event.target.value] } })
2 Replies
seekinfox
seekinfoxOP3y ago
Is there any way to use property like this?
Daryl
Daryl3y ago
You can try this:
function changeInput(...) {
// rest
setInput(prev => {
const result = {};
result[property] = [...prev[property], event.target.value];

return {...prev, ...result}
})
}
function changeInput(...) {
// rest
setInput(prev => {
const result = {};
result[property] = [...prev[property], event.target.value];

return {...prev, ...result}
})
}
Want results from more Discord servers?
Add your server