Skip to content

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

Merged
merged 3 commits into from
Apr 22, 2022

Conversation

SunLxy
Copy link
Contributor

@SunLxy SunLxy commented Apr 22, 2022

No description provided.

@vercel
Copy link

vercel bot commented Apr 22, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/398188662/react-code-preview/3jWW3fqsFQpCF2DqKV7jhW86EZyE
✅ Preview: https://react-code-preview-git-fork-sunlxy-master-398188662.vercel.app

@jaywcjlove
Copy link
Member

@SunLxy 为什么是临时解决。还有什么问题,需要描述清楚。

str = str.replace('_mount_', `document.getElementById('${playerId.current}')`);
// react < v18 中写法替换
str = str.replace('ReactDOM.render', `ReactDOMClient.createRoot("${playerId.current}").render`);
// react v18 中写法替换
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没有看到小于 18 的版本判断?

@jaywcjlove
Copy link
Member

@SunLxy 解决测试用例错误。

jaywcjlove added a commit that referenced this pull request Apr 22, 2022
github-actions bot added a commit that referenced this pull request Apr 22, 2022
@@ -1,4 +1,6 @@
import React, { useEffect, useRef } from 'react';
// @ts-ignore
import ReactDOMClient from 'react-dom/client';
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants