React Native Cannot read property ‘map‘ of undefined

学习React native开发中,自定义了一个组件,传参进来了一个数组tabList

想读取数组值的时候,tabList.map(item => item.component)一直报Cannot read property 'map' of undefined

后来发现,是无法直接识别tabList是个数组,需要先判断

可通过方法1:{(tabList || []).map(e => e.component)},或一个空数组来表示是个数组

方法2:{tabList && tabList.length > 0 && tabList.map(item => item.component)},先判断数组长度大于0来表示是个数组

你可能感兴趣的:(react,native,react.js,javascript)