接下來(lái)的一段時(shí)間內(nèi)我將帶大家,閱讀React 相關(guān)主要源碼,讓大家知其然,更要知其所以然。更好的利用React 進(jìn)行項(xiàng)目開(kāi)發(fā)
1、首先我們把github 上的react 包下載下來(lái)
github?地址:https://github.com/facebook/react
git clone?https://github.com/facebook/react.git
2、然后找到 入口:packages / react / src /? index.js,進(jìn)行分析

'use strict';
const React = require('./src/React');
// TODO: decide on the top-level export form.// This is hacky but makes it work with both Rollup and Jest.
module.exports = React.default || React;
從這里我們可以得知,src/中的Reac.js 才是真正的入口,其包含的對(duì)象如下
const React = {
? Children: {
? ? map,
? ? forEach,
? ? count,
? ? toArray,
? ? only,
? },
? createRef,
? Component,
? PureComponent,
? createContext,
? forwardRef,
? lazy,
? memo,
? useCallback,
? useContext,
? useEffect,
? useImperativeHandle,
? useDebugValue,
? useLayoutEffect,
? useMemo,
? useReducer,
? useRef,
? useState,
? Fragment: REACT_FRAGMENT_TYPE,
? StrictMode: REACT_STRICT_MODE_TYPE,
? Suspense: REACT_SUSPENSE_TYPE,
? createElement: __DEV__ ? createElementWithValidation : createElement,
? cloneElement: __DEV__ ? cloneElementWithValidation : cloneElement,
? createFactory: __DEV__ ? createFactoryWithValidation : createFactory,
? isValidElement: isValidElement,
? version: ReactVersion,
? unstable_ConcurrentMode: REACT_CONCURRENT_MODE_TYPE,
? unstable_Profiler: REACT_PROFILER_TYPE,
? __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: ReactSharedInternals,
};
下一節(jié),我將就我們最常用到的Component ,和PureComponent 進(jìn)行深入解析