Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Fix inconsistent behavior between setState in init and directly assigning to state #232

Merged
merged 4 commits into from
Aug 14, 2019

Conversation

ZoteTheMighty
Copy link
Contributor

@ZoteTheMighty ZoteTheMighty commented Aug 13, 2019

In Roact 1.x, setState is allowed during a component's init method. This change was made to unify all state changes and to further discourage direct mutation of state.

However, getDerivedStateFromProps remains an ever-present source of finicky corner cases. In the case that users were still assigning directly to state, they would actually lose any derived state that was supposed to be present by the time they rendered.

This actually breaks existing components migrating from Roact 0.2.0 to Roact 1.x. This change addresses that incompatibility.

Checklist before submitting:

  • Added entry to CHANGELOG.md
  • Added/updated relevant tests
  • Added/updated documentation

@ZoteTheMighty ZoteTheMighty changed the title Derived state nonsense Fix inconsistent behavior between setState in init and directly assigning to state Aug 13, 2019
@ZoteTheMighty ZoteTheMighty merged commit 986c1d5 into Roblox:master Aug 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants