此组件的渲染方法确实使用提供给组件的任何 Prop 。
组件是否会在 props 发生变化时重新渲染?
class MyComponent extends React.Component {
constructor(props) {
super(props);
const { propValue } = props;
// do something with propValue...
}
render () {
return (
<div>foo</div>
);
}
}
最佳答案
render
是否会被调用 - 是的。除非您实现 shouldComponentUpdate
以返回 false
。
DOM 是否会被重新渲染 - 不会。
您可能还想看看 https://babeljs.io/docs/plugins/transform-react-constant-elements/将静态元素提升。
In
const Hr = () => { return <hr className="hr" />; };
Out
const _ref = <hr className="hr" />; const Hr = () => { return _ref; };
关于javascript - 调用render方法时ReactJS是 "clever"吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45712278/