Javascript React.Component和React.PureComponent显示不同的行为
我在下面添加可运行的代码段。看到区别了吗 第一个是React.PureComponent版本Javascript React.Component和React.PureComponent显示不同的行为,javascript,reactjs,Javascript,Reactjs,我在下面添加可运行的代码段。看到区别了吗 第一个是React.PureComponent版本 类应用程序扩展了React.PureComponent{ render(){ console.log('re-render') 返回( 我是父母 {this.props.children} ) } } ReactDOM.render( 我是孩子 , document.getElementById('app') ) //设置超时(渲染,1000) 我可能错了,但我认为不会做出反应。PureComponen
类应用程序扩展了React.PureComponent{
render(){
console.log('re-render')
返回(
我是父母
{this.props.children}
)
}
}
ReactDOM.render(
我是孩子
,
document.getElementById('app')
)
//设置超时(渲染,1000)
我可能错了,但我认为
不会做出反应。PureComponent
存在于15.1.0版中
您得到的错误(“uncaughttypeerror:Super expression必须为null或函数,而不是未定义的”
)通常由输入错误或扩展不存在的类触发(请参阅中的更多详细信息)
我的建议是让您的第三方LIB保持最新,并在这种情况下使用最新版本的React
以下是您自己在react升级后的示例:
类应用程序扩展了React.PureComponent{
render(){
console.log('re-render')
返回(
我是父母
{this.props.children}
)
}
}
ReactDOM.render(
我是孩子
,
document.getElementById('app')
)
//设置超时(渲染,1000)
我可能错了,但我认为不会做出反应。PureComponent
存在于15.1.0版中
您得到的错误(“uncaughttypeerror:Super expression必须为null或函数,而不是未定义的”
)通常由输入错误或扩展不存在的类触发(请参阅中的更多详细信息)
我的建议是让您的第三方LIB保持最新,并在这种情况下使用最新版本的React
以下是您自己在react升级后的示例:
类应用程序扩展了React.PureComponent{
render(){
console.log('re-render')
返回(
我是父母
{this.props.children}
)
}
}
ReactDOM.render(
我是孩子
,
document.getElementById('app')
)
//设置超时(渲染,1000)
React.PureComponent在您的情况下不起作用,因为您使用的是旧版本的ReactJS。实际上,2016年6月29日,React 15.3引入了对React.PureComponent的支持。React.PureComponent在您的情况下不起作用,因为您使用的是旧版本的ReactJS。实际上,对React.PureComponent的支持是在2016年6月29日React 15.3中引入的。React.PureComponent是在15.3.0版本之后添加的,因为第一种情况下存在错误。
如果你想让你的第一个案例起作用,请检查代码片段。我已经更新了react版本
类应用程序扩展了React.PureComponent{
render(){
console.log('re-render')
返回(
我是父母
{this.props.children}
)
}
}
ReactDOM.render(
我是孩子
,
document.getElementById('app')
)
//设置超时(渲染,1000)
React.PureComponent是在15.3.0版本之后添加的,因为在第一种情况下存在错误。
如果你想让你的第一个案例起作用,请检查代码片段。我已经更新了react版本
类应用程序扩展了React.PureComponent{
render(){
console.log('re-render')
返回(
我是父母
{this.props.children}
)
}
}
ReactDOM.render(
我是孩子
,
document.getElementById('app')
)
//设置超时(渲染,1000)
我刚刚在JSFIDLE中尝试了您的第一个代码,它可以工作:(您使用的是哪个版本的react ar,我的FIDLE有15.1.0版本?)我刚刚在JSFIDLE中尝试了您的第一个代码,它可以工作:(您使用的是哪一版本的react ar,我的小提琴有15.1.0版本,PureComponent是在react 15.3中引入的回答谢谢,PureComponent是在react 15.3中引入的回答谢谢