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

Add getDerivedStateFromProps #57

Merged
merged 3 commits into from
Apr 5, 2018

Conversation

AmaranthineCodices
Copy link
Contributor

Fixes #53.

Adds a static class function, getDerivedStateFromProps, that is invoked when a component instance is created and when properties change. This function receives two arguments: newProps, the new properties table, and currentState, the component's current state (note that in cases where rendering causes both properties and state to change, currentState will equal the new state - I'm not sure if this happens in practice).

getDerivedStateFromProps may return either a table or nil; if it returns a table, the table is merged into the state without triggering another re-render. This is called before any lifecycle hooks invoke, including willUpdate.

@coveralls
Copy link

coveralls commented Apr 4, 2018

Coverage Status

Coverage increased (+0.6%) to 88.316% when pulling aeb8d99 on AmaranthineCodices:getDerivedState into bbb0663 on Roblox:master.


local handle = Reconciler.reify(Core.createElement(TestComponent, {
visible = true
}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can merge these two tests just by adding the two lines of assertion here I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed now!

@LPGhatguy LPGhatguy merged commit 5bad459 into Roblox:master Apr 5, 2018
@LPGhatguy
Copy link
Contributor

I'll handle the changelog and documentation -- I want to hold off on the latter until I actually get a chance to try porting Roact-Rodux to use this!

@LPGhatguy LPGhatguy mentioned this pull request Apr 5, 2018
2 tasks
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.

3 participants