Git Product home page Git Product logo

react-resource's Introduction

react 源码调试

目录结构

app:create-react-app 创建的项目,方便进行调试

build:react构建的文件,cjs文件下为构建后的未压缩的包,可以修改进行调试,但是没有热更新。一般不会修改,主要是用于梳理逻辑,常见是在浏览器中了解调用栈、打断点

packages:react 源码包,所有函数具体实现看这里

运行

  1. 创建软链接

进入build/modules/reactbuild/modules/react-dom,执行yarn link

注意之前有没有创建过,不能创建同名的。

  1. 链接软链

进入app目录,执行yarn link react react-dom来,app项目reactreact-dom的包就链接到了build目录下的文件

  1. 运行项目

进入app目录,执行yarn start

Troubleshooting

当使用 yarn link 建立软链时,在 app 中使用Hooks会报错:

Uncaught Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app

Resolve

改用yalc,就不会有问题。

  1. 全局安装yalc

yarn global add yalc

  1. 创建软链接

进入build/modules/reactbuild/modules/react-dom,执行yalc publish

  1. 链接软链

进入app目录,执行yalc add my-components

  1. 运行项目

react-resource's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.