Functions are not valid as a React child. This may happen if you return a Component instead of from render

后端 未结 8 2270
醉话见心
醉话见心 2020-12-04 20:54

I have written a Higher Order Component:

import React from \'react\';


const NewHOC = (PassedComponent) => {
    return class extends React.Component {
          


        
8条回答
  •  一个人的身影
    2020-12-04 21:24

    Adding to sagiv's answer, we should create the parent component in such a way that it can consist all children components rather than returning the child components in the way you were trying to return.

    Try to intentiate the parent component and pass the props inside it so that all children can use it like below

    const NewComponent = NewHOC(Movie);
    

    Here NewHOC is the parent component and all its child are going to use movie as props.

    But any way, you guyd6 have solved a problem for new react developers as this might be a problem that can come too and here is where they can find the solution for that.

提交回复
热议问题