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

Data: Allow undefined return from withSelect mapSelectToProps #5421

Merged
merged 2 commits into from
Mar 7, 2018

Conversation

aduth
Copy link
Member

@aduth aduth commented Mar 5, 2018

This pull request seeks to allow a falsey return value from a withSelect mapping function mapSelectToProps . This is a divergence from React Redux which enforces that this value be an object, leading to some awkward workarounds to ensure an object is returned. With these changes, a falsey value is assumed as equivalent to an empty object of props.

Further, the changes here resolve an issue where props may linger after a subsequent mapping call returns a different set of object keys. Previously we used a component's setState to update mapped props, but this behaves as a patch application. Previously React supported a this.replaceState method (deprecated in React 0.13) for this purpose, but it's easy enough to replicate with choosing an arbitrary key in state to apply the mapped value to.

Testing instructions:

Ensure unit tests pass:

npm run test-unit

@aduth aduth added the Framework Issues related to broader framework topics, especially as it relates to javascript label Mar 5, 2018
@aduth
Copy link
Member Author

aduth commented Mar 5, 2018

Noting that this behavior was anticipated as part of the documentation updates in #5379:

Specific implementation differences from Redux and React Redux:

[...]

  • In React Redux, a mapStateToProps function must return an object.
    • In @wordpress/data, a withSelect mapping function can return undefined if it has no props to inject.

@aduth aduth merged commit a468cf5 into master Mar 7, 2018
@aduth aduth deleted the update/with-select-return-undef branch March 7, 2018 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Framework Issues related to broader framework topics, especially as it relates to javascript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant