✅ – dk.dv – 17-33 Jan 20
Hi, beginner here, got an issue that probably has a simple solution but I'm not sure how to proceed:
In strict mode, all my components mount twice. In my main component, in
Normally, I'd just set a variable to check if mount has already been called / if a websocket connection is live, but given these functions are called asynchronously, it doesn't always work reliably. Using state also isn't working because saving state is also async, so even if I try to save a flag, it gets saved after both of the mount operations have already checked for it.
Is there a clean way to deal with this?
In strict mode, all my components mount twice. In my main component, in
componentDidMount(), I have a call to connect to a websocket server. This causes the app (in dev mode) to create two identical connections at the start.Normally, I'd just set a variable to check if mount has already been called / if a websocket connection is live, but given these functions are called asynchronously, it doesn't always work reliably. Using state also isn't working because saving state is also async, so even if I try to save a flag, it gets saved after both of the mount operations have already checked for it.
Is there a clean way to deal with this?
