After upgrading to 42 from 41, setting an object using useState is hanging parts of the screen

  1. SDK Version: 42
  2. Platforms(Android/iOS/web/all): Android emulator
  3. 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?

Hey @raselmat, this seems like it would be specific to react/react-native. What’s also interesting is the versions of those did not change between SDK41 and 42. Can you try reproducing this with vanilla React Native project?

Cheers,
Adam

Thank you for your reply Adam.

What’s also interesting is the versions of those did not change between SDK41 and 42

That’s exactly what’s making me surprised.

Can you try reproducing this with vanilla React Native project?

I will when I have a little bit of free time.

For the solution, I replaced currently all useState with useRef and it works without any problem. It’s a weird issue indeed!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.