-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
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
Throws an error when select
not returns an object
#85
Throws an error when select
not returns an object
#85
Conversation
On Connector, verify if `select` prop, which is a function, returns an object, and if not, throws an error. Issue reduxjs#78
@@ -59,6 +60,11 @@ export default function createConnector(React) { | |||
selectState({ context, props } = this) { | |||
const state = context.redux.getState(); | |||
const slice = props.select(state); | |||
|
|||
if (!isPlainObject(slice)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Let's use invariant
?
import invariant from 'invariant';
// ...
invariant(
isPlainObject(slice),
'The return value of `select` prop must be an object. Instead received %s.',
slice
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
👍 |
…ject Throws an error when `select` not returns an object
Awesome, thank you! |
Mb i'm wrong, but you need to add babel transform to strip invariant message in production like this https://github.com/facebook/react/blob/master/vendor/constants.js |
I actually don't mind having message in production (it's not that long and we only have very few). |
On Connector, verify if
select
prop, which is a function, returns anobject, and if not, throws an error.
Issue #78