React native: Cannot add a child that doesn't have a YogaNode or parent node

后端 未结 14 2182
忘掉有多难
忘掉有多难 2021-02-01 02:22

Just started learning react-native,

I have created one separate file flexdemo.js and created component as below:

import React, { Component } from \'react         


        
14条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 02:35

    In my case I had a condition in my render function that resulted in evaluating 0.

    It seems that 0 && 'some jsx' breaks in newer versions of react native.

    Error Example:

    render(){
       return 
                  {this.state.someArray.length && ...}
          
    }
    

    Although this should be valid javascript and works in react since 0 is falsey, It crashes in react native, not sure why but it works with a little refactoring as:

    Working Example:

    render(){
       return 
                  {this.state.someArray && this.state.someArray.length> 0 && 
                  ...}
              
    }
    

提交回复
热议问题