TypeError: undefined is not an object (evaluating '_react.default.defaultProps.object')

在 ReactNative 项目开发中,起初对组件属性进行检测的时候使用了 defaultProps 属性,但抛出了如上的异常提示

解决办法

将如上 defaultProps 属性替换为 React 中的 prop-types 的属性即可;
注:React 自从 V15.5 版本后将 prop-types 独立分离,所以需要单独引入;

首先,安装 prop-types

npm install --save prop-types

其次,引入 prop-types,此处区分 ES 6 或 ES 5,写法上稍有一些出入
ES 6 方式

import PropTypes from 'prop-types';

ES 5方式

var PropTypes = require('prop-types');

最后,将 defaultProps 的地方替换为 prop-types,在需要的地方调用即可

static propTypes = {item : PropTypes.object, width : PropTypes.number,height : PropTypes.number,backgroundColor : PropTypes.string,fontSize : PropTypes.number,// item : React.defaultProps.object, // width : React.defaultProps.number,// height : React.defaultProps.number,// backgroundColor : React.defaultProps.string,// fontSize : React.defaultProps.number,};

以上便是此次分享的全部内容,希望能对大家有所帮助!

TypeError: undefined is not an object (evaluating '_react.default.defaultProps.object') - RN相关推荐

  1. ReactNative报错null is not an object (evaluating '_rngesturehandlermodule.default.direction')

    程序报错: null is not an object (evaluating 'rngesturehandlermodule.default.direction') 解决: react-native ...

  2. React Native错误之 null is not an object (evaluating ‘_RNGestureHandlerModule.default.Direction)-坑

    错误:null is not an object (evaluating '_RNGestureHandlerModule.default.Direction) 原因:使用 react-navigat ...

  3. undefined is not an object(evaluating '_react3.default.PropTypes.shape)

    手机红屏报这个错时的解决办法: npm uninstall --save react-native-deprecated-custom-components npm install --save ht ...

  4. TypeError: undefined is not an object (evaluating 'o.type.name')

    uni-app启动报错,造成白屏,H5端正常,小程序和APP报错如下: reportJSException >>>> exception function:createInst ...

  5. TypeError: Router.use() requires a middleware function but got a Object报错解决

    1.在运行nodejs-mongodb项目时,项目报错 TypeError: Router.use() requires a middleware function but got a Object ...

  6. TypeError: descriptor ‘WhichOneof‘ requires a ‘google.protobuf.pyext._message.CMessage‘ object but r

    TypeError: descriptor 'WhichOneof' requires a 'google.protobuf.pyext._message.CMessage' object but r ...

  7. JS报错 Uncaught TypeError: undefined is not a function,解决

    Chrome调试报错:Uncaught TypeError: undefined is not a function,所有的数据都显示不出来 原因正如错误提示:调用了一个没有定义的方法,实际是一个空值 ...

  8. vue 单元测试报错之 undefined is not a constructor (evaluating 'expect(vmComponent.count).toBe(1)')

    下面是按照vue官方的例子,写的测试, // MyComponent.spec.js import Vue from 'vue' import MyComponent from '@/componen ...

  9. ECMA262 Edition5 Object,Object的属性和方法,Object.prototype的方法.

    ES5,为Object添加了一批方法.了解这些方法,可以更好的理解属性描述符的应用. 所以还是很有必要读一读的.另外,这些方法用起来还是蛮给力的. 暂时对于ES5,就只放出这些吧,希望对大家有所帮助. ...

最新文章

  1. cookie设置httponly属性防护XSS***
  2. mysql第五章事务_mysql 第五章 备份恢复
  3. java并发实战编程pdf_「原创」Java并发编程系列25 | 交换器Exchanger
  4. Dubbo 新编程模型之外部化配置
  5. 真静态和伪静态的区别
  6. 【牛客 - 331B】炫酷五子棋(STLset 或Hash,tricks,二维map标记)
  7. count(1),count(*),count(rowid)
  8. 怎么用鼠标选中java中table的某一行_为什么同事的工作效率那么高?学会这些鼠标双击技巧,你也可以的...
  9. 如何使用Affinity Designer for mac编辑矢量曲线和形状
  10. matlab语音去噪_如何使用XAudioPro对音频去噪
  11. opsForValue() 的 set 用法
  12. 手把手带你玩摄像头模组
  13. 关于windows 7 启动 security center
  14. 使用pdfobject预览pdf文件
  15. linux 找出僵尸进程,linux 查看僵尸进程
  16. 1062 最简分数 python
  17. 道里云公司网络虚拟化架构NVI技术开放源代码--序言
  18. Android Google原生语音识别
  19. Permute mac版 v3.7.2 文件格式转换器
  20. 被掰弯的线性函数,海王一样的logstic

热门文章

  1. 8Kpcm转16K、32K、44.1K等
  2. spring boot基于Springboot的球鞋调货管理系统设计与实现 毕业设计-附源码160942
  3. Java后台接收参数出现java.lang.Integer cannot be cast to java.lang.Double错误(已解决)
  4. java支付接口开发
  5. mysql按固定字符进行切割_MySQL:SQL按特定字符分隔切割或删除特定字符
  6. Android UI 自动化测试
  7. 根据遗传、健康饮食习惯和体育锻炼的影响因素预测成人身高
  8. SEH转化为C++异常三
  9. 0基础转行网络安全,选择pwn还是web?
  10. 3.网络编程 网络编程