question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

must return an object. Instead received [object Object].

See original GitHub issue

hi,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:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
gaearoncommented, Apr 5, 2016

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 like state.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 pass state.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.

0reactions
EasonWang01commented, Apr 13, 2016

thanks!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found