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

后端 未结 8 2269
醉话见心
醉话见心 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:31

    In my case i forgot to add the () after the function name inside the render function of a react component

    public render() {
           let ctrl = (
               <>
                    
    {this.renderView}
    ); return ctrl; }; private renderView() : JSX.Element { // some html };

    Changing the render method, as it states in the error message to

            
    {this.renderView()}

    fixed the problem

提交回复
热议问题