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来表示是个数组

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-01 17:16:02       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-01 17:16:02       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-01 17:16:02       87 阅读
  4. Python语言-面向对象

    2024-02-01 17:16:02       96 阅读

热门阅读

  1. STM32——智能小车

    2024-02-01 17:16:02       41 阅读
  2. js中类型的值相加或相减的转换

    2024-02-01 17:16:02       49 阅读
  3. KY104 Pre-Post

    2024-02-01 17:16:02       64 阅读
  4. OpenGL着色器对象 Shader Objects

    2024-02-01 17:16:02       58 阅读
  5. Leetcode刷题(三十一)

    2024-02-01 17:16:02       50 阅读
  6. 【笔记ing】Helm-5 Chart模板指南-5 模板函数列表

    2024-02-01 17:16:02       60 阅读
  7. unity 讯飞webapi在线语音合成

    2024-02-01 17:16:02       54 阅读
  8. pip install matplotlib

    2024-02-01 17:16:02       69 阅读