【问题标题】:Functions are not valid as a react child.This may happen if you return a component instead of <Component/> from render函数作为反应子级无效。如果您从渲染返回一个组件而不是 <Component/> ,则可能会发生这种情况
【发布时间】:2020-01-09 13:34:56
【问题描述】:

我收到这个错误,它把我引向这个函数作为 React Child 无效。如果你返回一个组件而不是从渲染中返回,这可能会发生。 我该如何解决这个问题?或者去解决这个问题,请帮忙!!!

    const App: () => React$Node = () => {
      return (

      <View >
          <Main {...this.props}/>
      </View>



And this is my Main component

    import React,{Component} from 'react';
    import {View,Text} from 'react-native';
    import createStore from './store/createStore';
    import AppContainer from './AppContainer';

    export default class Main extends Component{
        renderApp(){
           const initalState=window.__INITIAL_STATE__;
            const store=createStore(initalState);

        return(
            <AppContainer store={store}/>
        );

    }
    render(){
        return this.renderApp;
    }
}

  );
};

【问题讨论】:

    标签: android reactjs react-native


    【解决方案1】:

    试试return this.renderApp(),这样你就可以真正执行函数了

    【讨论】:

      【解决方案2】:

      把你的主要组件改成这个

      export default class Main extends Component{
              renderApp = () =>{
                 const initalState=window.__INITIAL_STATE__;
                  const store=createStore(initalState);
      
              return(
                  <AppContainer store={store}/>
              );
      
          }
          render(){
              return this.renderApp();
          }
      }
      

      希望对你有帮助

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-12-26
        • 1970-01-01
        • 1970-01-01
        • 2020-02-20
        • 2018-11-22
        • 1970-01-01
        • 2018-12-01
        相关资源
        最近更新 更多