1
上。這裏JS生命週期方法是一個組件:陣營未擊發裹組件
export default class MyComponent extends React.Component {
componentWillReceiveProps(newProps) {
console.log('RECEIVED PROPS');
}
render() {
return <div>{this.props.foo}</div>
}
}
這裏是一個包裝/高階分量:
const withSomething = (ComponentToWrap) => {
render() {
return <ComponentToWrap {...this.props} />
}
}
這裏是一個封裝MyComponent的功能部件in withSomething:
export default function WrappedComponent(props) {
const Component = withSomething(MyComponent);
return <Component ... some props ... />
}
結果:與道具相關的生命週期函數(如componentWillReceiveProp s)在MyComponent中永遠不會開火,即使我更新道具。
這是怎麼回事?基於道具的生命週期方法不適用於包裝組件嗎?