score:4
I see two problems in your data
constant. The first one, the .map
method returns an array, so there is no need to wrap that value inside an array keys []
. The other problem is that you are wrapping the .map
return state object in array keys too, that is why the error of creating an object is displayed, because you are returning arrays inside the main mapped array [[{ name: ... }], [{ name: ... }]]
.
So basically the solution for your issue would be:
const data = posts.map(post => ({name: 'post.firstname', dateregistered: 'post.date', department: 'post.department'}))
Where the parenthesis allows the map method to directly return the object.
score:1
The issue is that data is being created as an array in an array in an array. This is why when you try const data = posts.map(post => ...)
the error persists, as there is still an array in an array. After you try the above, also re-write
post => [{name: 'post.firstname', dateregistered: 'post.date', department: 'post.department'}]
to
post => ({name: 'post.firstname', dateregistered: 'post.date', department: 'post.department'})
(Changing the square brackets to round)
P.S When you map over posts to build the data, you build a object with the the key "name" and the value "'post.firstname'". That value is a string literal and not accessing some other JS object (It will make "post.firstname" the value for all the post's. Same goes for the other keys.
Source: stackoverflow.com
Related Query
- Objects are not valid as a React child (found: object with keys {username}). If you meant to render a collection of children, use an array instead
- Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {name}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {job}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {totalItems}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {arr}). If you meant to render a collection of children, use an array instead
- Error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead. JS
- Objects are not valid as a React child (found: object with keys {weight}). If you meant to render a collection of children, use an array instead
- Error: Objects are not valid as a React child (found: object with keys {name}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {children}). If you meant to render a collection of children, use an array instead
- Error: Objects are not valid as a React child (found: object with keys {value}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {items}). If you meant to render a collection of children, use an array instead
- My error: Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead
- How to fix Objects are not valid as a React child (found: object with keys {}). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {})/If you meant to render a collection of children, use an array instead. Help me?
- Uncaught Error: Objects are not valid as a React child (found: object with keys {todo}). If you meant to render a collection of children, use an array
- Objects are not valid as a React child (found: object with keys {id, name}). If you meant to render a collection of children, use an array instead
- React native - objects are not valid as a React child (found: object with keys {$$typeof, type, key, ref, props, _owner, _store})
- Objects are not valid as a React child (found: object with keys {})
- Objects are not valid as a React child (found: object with keys {children}): ReactJS
- React.js Error: " Objects are not valid as a React child (found: object with keys {})."
- Error: Objects are not valid as a React child (found: object with keys {id, name})
- Error: Objects are not valid as a React child (found: object with keys {$$typeof, type, compare, WrappedComponent, displayName})
- Error: Objects are not valid as a React child (found: object with keys {}). use an array instead
- Error: Objects are not valid as a React child (found: object with keys {})
- React with Router v5 Error: Objects are not valid as a React child (found: object with keys {children})
- Objects are not valid as a React child (found: object with keys). If you meant to render a collection of children, use an array instead
- Objects are not valid as a React child (found: object with keys {children})
- 'Error: Objects are not valid as a React child (found: object with keys {results, info})'
- Error: Objects are not valid as a React child (found: object with keys {zip})
More Query from same tag
- ”Warning: Function components cannot be given refs.“ error while using custom component in nextjs
- Froala React component throwing "cannot set property 'more_btn' of undefined"
- How to add a tab dynamically when we click a button using React js and Bootsrap 4
- How to make a request after the variable changes
- Material-UI withStyles not applying background color
- ContextProvider => Context APi : Children dynamically rendered
- IndexRoute doesn't seem to work
- React Constants inside a Function
- Serve static react app with nodejs through docker
- How to create test on a non inline style CSS in a jest
- React.PropTypes is deprecated and I have installed prop-types package
- Insert data using multiple components in reactjs
- Correct type for children props in wrapper class?
- How can I integrate searching functionality on table?
- React-Redux: Add custom third parameter to mapStateToProps - possibly connectAdvanced?
- Style sheet is not styling React Component
- Manipulating state with useEffect, but not correctly rendering updated from updated state
- Hide parent component in react-router
- How to fix the date[] is not assignable to type [date?, date?] in react hook
- Show the selected option as the first option in the select dropdown?
- eslint error "Must use destructuring props assignment "
- how to show the contents in one ui using reactjs
- Storing data from Axios Promise for multiple uses
- Material-UI Change Drawer Color
- React: Design pattern that uses a Ref to set style of the parent component
- React how to display ErrorMessage in Input Form
- InvalidCharacterError: Failed to execute 'createElement' on 'Document':The tag name provided ('/static/media/avatar.6043f57a.png') is not a valid name
- is it okay to pass large variable into React state?
- setSomeState() called from a catch() function doesn't update
- How to get the original original Default Arrangement from sorted array?