must return an object. Instead received [object Object].
See original GitHub issuehi,I’m new to this
the error message is
browser.js:40 Uncaught Invariant Violation:
mapStateToPropsmust return an object. Instead received [object Object].
1.
case 'TOGGLE_TODO':
return state.todos.map(function(state){
if(state.id!==action.id){
return state
};
return {...state,completed:true}
});
(from egghead ) this will throw the error,but I don’t know why.
But if I not using return
before state.todos.map
it is fine
case 'TOGGLE_TODO':
state.todos.map(function(state){
if(state.id!==action.id){
return state
};
//return state.completed=true}
return {...state,completed:true}
});
if I change to this it will not change the store
only
case 'TOGGLE_TODO':
state.todos.map(function(state){
if(state.id!==action.id){
return state
};
//return state.completed=true}
return state.completed=true
});
and
case 'TOGGLE_TODO':
state.todos.map(function(state){
if(state.id!==action.id){
return state
};
//return state.completed=true}
return Object.assign(state,{completed:true})
});
can successfully update the store and no error message,but this will also change the prev state,
how can I change this code? Thanks for reply.
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (4 by maintainers)
Top Results From Across the Web
mapStateToProps() in connect() must return a plain object ...
Im getting an error at the end as 'mapStateToProps must receive a plain object, Instead received Undefined'. please let me know how to...
Read more >Resolving React Error, "Tried to merge an object, instead got ...
While working with state variables in React, you might run into an error stating Tried to merge an object, instead got [object Object]...
Read more >mapStateToProps must return an object. Instead received Map ...
This github issue covers this exact problem: https://github.com/reactjs/react-redux/issues/60. You can manually extract the values you want from your Map in ...
Read more >Understanding the "Objects are not valid as a react child" Error ...
Wrap Up · No .map() method was called to render a collection of items from an array. · An object is being returned...
Read more >Connect | React Redux
The results of mapStateToProps must be a plain object, which will be merged into the ... i.e., you return a function instead of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Why are you posting the reducer code? The error says
mapStateToProps
returned something that isn’t a plain object. Not the reducer.My guess is your
mapStateToProps
returns something likestate.todos
which will not work. The point of that function is to provide props to component, so it has to return an object with those props. Rather than passstate.todos
you would probably want{ todos: state.todos }
.If this is the case, we need to make a better error message that detects arrays. Contributions are welcome.
thanks!