-
Couldn't load subscription status.
- Fork 191
feat: add React/render util #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/react-component/util/GN25CVzNHK1qvE7AdkjZVYiq3xKk |
Codecov Report
@@ Coverage Diff @@
## master #292 +/- ##
==========================================
+ Coverage 64.04% 65.02% +0.97%
==========================================
Files 44 45 +1
Lines 940 972 +32
Branches 329 325 -4
==========================================
+ Hits 602 632 +30
- Misses 300 302 +2
Partials 38 38
📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more |
| // Do nothing; | ||
| } | ||
|
|
||
| const MARK = '__rc_react_root__'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用个 Symbol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Symbol IE 不兼容
| try { | ||
| const mainVersion = Number((version || '').split('.')[0]); | ||
| if (mainVersion >= 18) { | ||
| ({ createRoot } = require('react-dom/client')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 require 会不会对工具链有要求?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
比如 webpack 和 vite。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有,不过 import 本身也是需要工具链来处理的。转换后其实其实 require:https://unpkg.com/browse/antd@4.19.5/lib/affix/index.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
干脆直接用 ReactDOM 里的 createRoot 好了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ReactDOM 的 createRoot 会在 console 打 warning,让你用 react-dom/client 的 createRoot:
Warning: You are importing createRoot from "react-dom" which is not supported. You should instead import it from "react-dom/client". react-dom.development.js:73
No description provided.