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

Remove all null initial states in redux reducers #410

Open
patcon opened this issue Jul 10, 2020 · 0 comments
Open

Remove all null initial states in redux reducers #410

patcon opened this issue Jul 10, 2020 · 0 comments

Comments

@patcon
Copy link
Contributor

patcon commented Jul 10, 2020

Seems that to properly use prop-types, react doesn't play nicely with props that start as null but later become a specific form. This keeps us from using prop-types as effectively as we could be using them (e.g., making generous use of .isRequired and ensuring presence of defaultProps values whenever a value isn't required.)

You can trace the story from here, but there have been many workarounds over years:
facebook/react#2166 (comment)

My impression is that null isn't really supported in the ways we're using it in places like this:

https://github.com/pol-is/polisServer/blob/577dec6407470147b1c9043293ee30b85c6b335b/client-admin/src/reducers/mod_comments_accepted.js#L5-L8

where we then look for null to track when things are still loading:

https://github.com/pol-is/polisServer/blob/133e3d3b6c07ca1fddd27c414f25b382ffddc7d0/client-admin/src/components/conversation-admin/conversation-has-comments-check.js#L41

We should probably be doing one of two things:

  1. something like this to track isLoading state outside looking for a null value:
    https://medium.com/stashaway-engineering/react-redux-tips-better-way-to-handle-loading-flags-in-your-reducers-afda42a804c6

  2. Or using explicitNull custom prop-type from airbnb:
    Add isDefined and isNotNull parallels to isRequired facebook/prop-types#90 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant