美文网首页
React 源码解析(V16.8.4)概览

React 源码解析(V16.8.4)概览

作者: curliu | 来源:发表于2019-03-09 17:51 被阅读0次

接下来的一段时间内我将带大家,阅读React 相关主要源码,让大家知其然,更要知其所以然。更好的利用React 进行项目开发

1、首先我们把github 上的react 包下载下来

github 地址:https://github.com/facebook/react

git clone https://github.com/facebook/react.git

2、然后找到 入口:packages / react / src /  index.js,进行分析

'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 才是真正的入口,其包含的对象如下

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,

};

下一节,我将就我们最常用到的Component ,和PureComponent 进行深入解析

相关文章

网友评论

      本文标题:React 源码解析(V16.8.4)概览

      本文链接:https://www.haomeiwen.com/subject/djyspqtx.html