DEV Community

kennyLFC
kennyLFC

Posted on

error on rendering an array of items using redux

ive trying to render an array of items using redux and encountered the error below. the following is what ive done

Objects are not valid as a React child (found: object with keys {userlist}). If you meant to render a collection of children, use an array instead.

1) search actions file

search action

search reducer

Alt Text

Top comments (3)

Collapse
 
vonheikemen profile image
Heiker • Edited

const {searchresults} = this.props.searchresults assumes that the shape of your object is:

{
  "searchresults": {
    "searchresults": [/* stuff */]
  }
}

I'm not sure that's the case. Did you try const {searchresults} = this.props;

It would help a lot with this type of questions if you could reproduce the error, put in codepen or stackblitz and share the link in your post.

Collapse
 
kenethsimon profile image
kennyLFC
Collapse
 
vonheikemen profile image
Heiker

The error message suggest that something you think is an array is actually an object and you are trying to render that. You may have to inspect everything in that render function in SearchBar. I would start with this.props.