Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove potential race conditions from setState changes #2474

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

brianoqr
Copy link

@brianoqr brianoqr commented Feb 1, 2024

Hi, so i was using react-native-gifted-chat and had a race condition because my stream of messages happened at the same time as the "onLayout" event which made the isInitialized variable remain false as it was overwritten by a stale state value when the messages array was updated at the same time as onLayout. This happens because setState is being called using a the local state value.

I updated all the setState functions to use the state value passed by the function which is always up to date so you don't have any possibility of writing to state with a stale value.

@brianoqr brianoqr changed the title fix: Make remove potential race conditions from setState changes fix: Remove potential race conditions from setState changes Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants