Skip to content

Fix Uncaught Error Objects are not valid as a React child

This error might happen because you’ve got a React component and you’re rendering a prop in the JSX, like this, but you forgot to destructure the prop when initializing the component parameters:

function MyComponent(test) {
	return <p>{test}</p>
}

You should do this instead:

function MyComponent({ test }) {
	return <p>{test}</p>
}

The component receives a props object and we commonly use object destructuring to get the props “mapped” to variables, like {test} in our example.


→ Get my React Beginner's Handbook

I wrote 21 books to help you become a better developer:

  • HTML Handbook
  • Next.js Pages Router Handbook
  • Alpine.js Handbook
  • HTMX Handbook
  • TypeScript Handbook
  • React Handbook
  • SQL Handbook
  • Git Cheat Sheet
  • Laravel Handbook
  • Express Handbook
  • Swift Handbook
  • Go Handbook
  • PHP Handbook
  • Python Handbook
  • Linux Commands Handbook
  • C Handbook
  • JavaScript Handbook
  • Svelte Handbook
  • CSS Handbook
  • Node.js Handbook
  • Vue Handbook
...download them all now!

Related posts that talk about react: