Error: Objects are not valid as a React child (found: [object Promise])
Dung Do Tien
Oct 31 2022
331
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.
-
D1
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 }
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.