I have a component:
const MyComp : React.FC<{ editing?: Data }> = ({editing = { title = '', description = '', date: new Date() } }) => {
const [data, setData] = useState<Data>({...editing})
useEffect(() => setData({...editing}), [editing])
return (/* use data inside here to render component */)
}
The problem is that the useEffect is looping, so React is detecting that the editing prop is changing every, the thing is that i use MyComp without any props like this:
<MyComp></MyComp>
This is really confusing me, i'm kinda lost now on how React works, any ideas on why is this happening?
editingis not specified as a prop, the default will be used. And it'll be a different default instance for each render and that will see the effect run and that will set the state and that will render ...