Error: Objects are not valid as a React child (found: [object Promise])

Dung Do Tien Oct 31 2022 37

Hi guy!

I am processing a React component, and I have an error.

Unhandled Runtime 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.

This is my code:

  const Content = () => {
  const { data,error } = getContent(contentId)

  if (error === 1001) {
    push(routes.detailCourse.generatePath(Number(query.courseId)))
  }

  return (
      <div className="bg-course-detail bg-center bg-cover" />
  )
}

export default Content

I don't understand and don't know that its means. Please help me if you have any solution.

Have 1 answer(s) found.
  • D

    Dung Do Tien Oct 16 2022

    React doesn't understand this is React component

    Because you don't set return in if condition. You can try to fix it like this:

     if (error === 1001) {
      push(routes.detailCourse.generatePath(Number(query.courseId)))
      return null
    }

     

Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close