Categories
React Answers

How to fix Objects are not valid as a React child (found: [object Promise]) error?

Spread the love

Sometimes, we want to fix Objects are not valid as a React child (found: [object Promise]) error.

in this article, we’ll look at how to fix Objects are not valid as a React child (found: [object Promise]) error.

How to fix Objects are not valid as a React child (found: [object Promise]) error?

To fix Objects are not valid as a React child (found: [object Promise]) error, we sure make sure we aren’t creating function components with async functions.

For instance, we write

const HelloApp = (props) => {
  return (
    <div>
      <h2>Hello World</h2>
    </div>
  );
};
ReactDOM.render(<HelloApp />, document.querySelector("#app"));

to create the HelloApp component with a regular JavaScript function.

Then this error should go away since regular functions can return JSX.

Conclusion

To fix Objects are not valid as a React child (found: [object Promise]) error, we sure make sure we aren’t creating function components with async functions.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.