React 的源代码中定义的生命周期方法在哪里?
Where are lifecycle methods defined in React's source code?
shouldComponentUpdate
和 React 源代码中定义的其他生命周期函数在哪里?我正在研究反应源代码,根本找不到定义..任何人都可以给出提示吗?
或者这样说:具体在哪里做出反应决定 return
shouldComponentUpdate
?
生命周期方法不是 'defined' 在 React 的代码中,可以这么说 - 它只是检查它们是否在组件实例的生命周期中的某些点存在,如果存在,它会运行它们。
例如,这里是 some of the code from the React reconciler package that checks shouldComponentUpdate
:
if (typeof instance.shouldComponentUpdate === 'function') {
startPhaseTimer(workInProgress, 'shouldComponentUpdate');
const shouldUpdate = instance.shouldComponentUpdate(
newProps,
newState,
newContext,
);
stopPhaseTimer();
/* ...and so on... */
return shouldUpdate;
}
shouldComponentUpdate
和 React 源代码中定义的其他生命周期函数在哪里?我正在研究反应源代码,根本找不到定义..任何人都可以给出提示吗?
或者这样说:具体在哪里做出反应决定 return
shouldComponentUpdate
?
生命周期方法不是 'defined' 在 React 的代码中,可以这么说 - 它只是检查它们是否在组件实例的生命周期中的某些点存在,如果存在,它会运行它们。
例如,这里是 some of the code from the React reconciler package that checks shouldComponentUpdate
:
if (typeof instance.shouldComponentUpdate === 'function') {
startPhaseTimer(workInProgress, 'shouldComponentUpdate');
const shouldUpdate = instance.shouldComponentUpdate(
newProps,
newState,
newContext,
);
stopPhaseTimer();
/* ...and so on... */
return shouldUpdate;
}