react更新props后this.props === nextProps
来源:互联网 发布:windows字体怎么设置 编辑:程序博客网 时间:2024/06/06 05:26
1. this.props always equals to nextProps
结构:父组件:ComparisonChart,子组件:UniversalChart
问题:父组件中state>data传到子组件作为props>data,但是在子组件的shouldComponentUpdate中,this.props和nextProps总是相等。
原因:
// 问题所在const { data } = this.state...data.push(..)this.setState({ data })// 写改为const data = [...this.state.data]
const { data } = this.state
其实只是对state.data进行了浅拷贝,此时data指向了state.data的地址,所以data.push(..)
已经导致state.data的值改变了,所以this.setState({ data })
导致的子组件更新时,this.props和nextProps一样。
参考:
- After updating props, this.props is always === nextProps / prevProps:
阅读全文
0 0
- react更新props后this.props === nextProps
- react this.props.children
- (props=>componentWillReceiveProps) !=>(componentWillReceiveProps=>props)
- react native -- this.props.children
- React.js--this.props.children
- React list this.props.children
- React props
- React Props
- react教程之this.props.children
- react教程序之this.props.children
- React Native的this.props获取属性
- React学习(五)this.props.children
- react教程之this.props.children
- React学习笔记(2)-React.createClass、this.props.children
- React传递Props
- react props传值
- React传递props
- React 之props属性
- promise_ajax封装
- vue生命周期详解
- Python开发者必备6个基本库
- 查询数据库当天某时间段数据
- c++11 class enum
- react更新props后this.props === nextProps
- on_exit()函数使用说明
- Unity3D Shader的几种基本编程方式
- 36、C#学习笔记2
- 数字图像处理-小波变换小白解释基本原则
- 如何获取登录Oracle数据库的客户端IP等会话信息
- Java开发中的23种设计模式详解(转)
- Python作用域与带有循环变量的默认参数相比较
- android 加载gif动图 自定义GifView