Hello, im quite new to react js and im struggling with this error: " Error: Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead. " Show I created the basic react app by running "npx create-react-app name-of-app" my code is:
in the console.log, "rows" return an array that looks like this: https://imgur.com/a/NJESUP2 , and I would simply like to display 'First status in workshop' in a <h2> bracket. Im looking for a simple way to do this, but im not sure how to solve this error. If I made anything unclear, please ask! thanks for any help I'm trying to access the review object from reviews.js in FirstReview.js to display the author and content but seem to be having some trouble and dont understand why. ERROR: Error: Objects are not valid as a React child (found: object with keys {roles, _id, username, email, password, __v}). If you meant to render a collection of children, use an array instead. The error seems to occur from the way I'm accessing props in FirstReview.js in the authot and content section of Comment. However I'm unsure as to how I've accessed props.review incorrectly and why the error is displaying the User object reviews.js
FirstReview.js
How do you fix objects are not valid as a React child?The React. js error "Objects are not valid as a React child" occurs when we try to directly render an object or an array in our JSX code. To solve the error, use the map() method to render arrays or access properties on the object in your JSX code.
How do you render collection of children React?If you meant to render a collection of children, use an array instead' Error. We can fix the 'Objects are not valid as a React child. If you meant to render a collection of children, use an array instead' error by rendering an array with the map method or render objects as strings or render the properties individually.
How do you pass an array of objects as a prop in React?To pass an array as a prop to a component in React, wrap the array in curly braces, e.g. <Books arr={['A', 'B', 'C']} /> . The child component can perform custom logic on the array or use the map() method to render the array's elements.
What is a React child?What are children? The children, in React, refer to the generic box whose contents are unknown until they're passed from the parent component. What does this mean? It simply means that the component will display whatever is included in between the opening and closing tags while invoking the component.
|