javascript - Component is not rendering in react js - Stack Overflow

Why this ponent is not rendering in react js.It shows the error messageUnhandled Runtime ErrorError:

Why this ponent is not rendering in react js.It shows the error message Unhandled Runtime Error Error: Element type is invalid: expected a string (for built-in ponents) or a class/function (for posite ponents) but got: object. You likely forgot to export your ponent from the file it's defined in, or you might have mixed up default and named imports.

This is my ponent

function Test({session}) {
    const RenderPage=fetchComment &&(
                fetchComment?.map((ment)=>{
                    return <LoadComment
                    key={i}
                    timestamp={ment.timestamp?.toDate()}
                    ment={mentment}
                    image={ment.image}
                    user={ment.user} />
                })
                )
return (
<RenderPage></RenderPage>
)
}

Why this ponent is not rendering in react js.It shows the error message Unhandled Runtime Error Error: Element type is invalid: expected a string (for built-in ponents) or a class/function (for posite ponents) but got: object. You likely forgot to export your ponent from the file it's defined in, or you might have mixed up default and named imports.

This is my ponent

function Test({session}) {
    const RenderPage=fetchComment &&(
                fetchComment?.map((ment)=>{
                    return <LoadComment
                    key={i}
                    timestamp={ment.timestamp?.toDate()}
                    ment={ment.ment}
                    image={ment.image}
                    user={ment.user} />
                })
                )
return (
<RenderPage></RenderPage>
)
}
Share Improve this question asked Dec 3, 2021 at 6:48 JeevanJeevan 491 silver badge9 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 2
return (
{RenderPage}
)

change the return statement. since its a variable not a ponent.

RenderPage isn't a valid React ponent, it is either falsey if fetchComment is undefined/falsey, or it is an array of JSX. Just return the puted RenderPage value. I suggest also un-PascalCasing the variable to alleviate any future reading confusion, convert back to camelCase. And to cover the case where you aren't returning an array, conditionally return null for valid JSX return from Test ponent.

function Test({session}) {
  const renderPage = fetchComment ? fetchComment.map((ment, i) => {
    return (
      <LoadComment
        key={i}
        timestamp={ment.timestamp?.toDate()}
        ment={ment.ment}
        image={ment.image}
        user={ment.user}
      />
    );
  }) : null;
  return renderPage;
}

Use

export default Test({session}) {
const RenderPage=fetchComment &&(
            fetchComment?.map((ment)=>{
                return <LoadComment
                key={i}
                timestamp={ment.timestamp?.toDate()}
                ment={ment.ment}
                image={ment.image}
                user={ment.user} />
            })
            )
return (
   {RenderPage}
 )

}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745445086a4628011.html

相关推荐

  • javascript - Component is not rendering in react js - Stack Overflow

    Why this ponent is not rendering in react js.It shows the error messageUnhandled Runtime ErrorError:

    7小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信