-
-
Notifications
You must be signed in to change notification settings - Fork 11
feat:临时解决react v18中报错问题方案 #214
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/398188662/react-code-preview/3jWW3fqsFQpCF2DqKV7jhW86EZyE |
@SunLxy 为什么是临时解决。还有什么问题,需要描述清楚。 |
src/useCodePreview.ts
Outdated
str = str.replace('_mount_', `document.getElementById('${playerId.current}')`); | ||
// react < v18 中写法替换 | ||
str = str.replace('ReactDOM.render', `ReactDOMClient.createRoot("${playerId.current}").render`); | ||
// react v18 中写法替换 |
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.
没有看到小于 18 的版本判断?
@SunLxy 解决测试用例错误。 |
@@ -1,4 +1,6 @@ | |||
import React, { useEffect, useRef } from 'react'; | |||
// @ts-ignore | |||
import ReactDOMClient from '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.
不能这样直接引用,如果在 react 17 中引入,import('react-dom')
或者 import('react-dom/client')
使用 try catch
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.
No description provided.