I've created a state of objects in React, but I need to increase an other object into the same state. However, i can't use the setState()
property because its causes a re-render (infinite loop).
My state:
const [testObject, setTestObject] = useState({
id: 0,
telephone: 123,
personalData: {
name: '',
alias: '',
gender: ''
}
})
The error:
Too many re-renders. React limits the number of renders to prevent an infinite loop.
I tried to find a solution for it, but i can't solve it:
setTestObject({...testObject, personalData: {
...testObject, name: 'McDonnell DC-10'
}})
Where am i wrong?