- SDK Version: 42
- Platforms(Android/iOS/web/all): Android emulator
- Add the appropriate “Tag” based on what Expo library you have a question on. useState with objects.
Very weird bug came up after upgrading from 41 to 42.
I have a child component that is sending data to a parent, the parent is using useState to set an object with the received data. When I use setState({_id: id, name: name}), the screen hangs (I can’t bo back, and console.log stops functionning, the rest is OK). I thought it’s the value of “state” that I am using somewhere else is causing the problem, but it wasn’t. I have created a new state that is not used anywhere as such:
const [state1, setState1] = useState<{_id: string | null, name: string | null}>({_id: "", name: ""})
Then in the parent component, I set the value received from the child:
setState1({_id: _id, name: name}) // HERE IT HANGS
If I use:
setId(_id);
setName(name);
it works without any issue. The problem is happening ONLY when I set the state of an object, anything else work without any problem!
That’s a snack to explain what I am exactly doing. In this snack, it works fine, not in Expo Go.
Any idea?