shouldComponentUpdate
在 React Native 中不起作用,还是我遗漏了什么?我只是想记录参数以便我可以比较,但它甚至没有被记录。当我运行 JS 时,我看到的只是“######## 渲染被调用”。
import React, { Component } from 'react';
class MyComponent extends Component {
constructor(props) {
super(props);
this.state = {}
}
shouldComponentUpdate(nextProps, nextState) {
console.log("######### shouldComponentUpdate called");
console.log(nextProps);
return true;
}
render() {
console.log("######### render called");
return <SomeJSX>
}
}
export default MyComponent;
最佳答案
shouldComponentUpdate
是 update
阶段的一部分,因此您必须更改 props
或 state
才能获取所需的输出。查看文档 here
关于javascript - 无法让 shouldComponentUpdate() 在 native react 中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49269705/