From b02daba399f0dcd6e757867f20ca22fa48dff301 Mon Sep 17 00:00:00 2001 From: jasonzhuang Date: Fri, 10 May 2024 10:07:55 +0800 Subject: [PATCH] feat: support react 18 (#2515) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 升级react 18 * 忽略.history * 忽略.history * build the project with react18 * change package.json version to 3.0.0 * 不修改code style, 不手动改版本号 * 不修改code style, 回滚代码样式格式化 * chore: code style * chore: code style --------- Co-authored-by: yougen Co-authored-by: sorrycc --- .gitignore | 1 + docs/guide/source-code-explore.md | 4 ++-- package.json | 4 ++-- packages/dva/package.json | 4 ++-- packages/dva/src/index.js | 4 ++-- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 1b6af44e..ca9d54ff 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /packages/**/node_modules /packages/**/dist /lerna-debug.log + diff --git a/docs/guide/source-code-explore.md b/docs/guide/source-code-explore.md index d276e474..c9f47b05 100644 --- a/docs/guide/source-code-explore.md +++ b/docs/guide/source-code-explore.md @@ -222,8 +222,8 @@ function getProvider(store, app, router) { // 真正的 react 在这里 function render(container, store, app, router) { - const ReactDOM = require('react-dom'); // eslint-disable-line - ReactDOM.render(React.createElement(getProvider(store, app, router)), container); + const ReactDOM = require('react-dom/client') // eslint-disable-line + ReactDOM.createRoot(container).render(React.createElement(getProvider(store, app, router))); } ``` diff --git a/package.json b/package.json index 8c90cced..1b5e6a0e 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,8 @@ "lerna-changelog": "^0.8.0", "lint-staged": "^7.2.2", "prettier": "^1.14.3", - "react": "^16.8.4", - "react-dom": "^16.8.4", + "react": "^18.0.0", + "react-dom": "^18.0.0", "react-testing-library": "^6.0.0", "shelljs": "^0.8.1", "umi-test": "^1.5.2" diff --git a/packages/dva/package.json b/packages/dva/package.json index 8c236259..f856e790 100644 --- a/packages/dva/package.json +++ b/packages/dva/package.json @@ -45,8 +45,8 @@ "redux": "^4.0.1" }, "peerDependencies": { - "react": "^16.8.4", - "react-dom": "^16.8.4" + "react": ">=18", + "react-dom": ">=18" }, "files": [ "dist", diff --git a/packages/dva/src/index.js b/packages/dva/src/index.js index f66af8d9..e7175671 100644 --- a/packages/dva/src/index.js +++ b/packages/dva/src/index.js @@ -99,8 +99,8 @@ function getProvider(store, app, router) { } function render(container, store, app, router) { - const ReactDOM = require('react-dom'); // eslint-disable-line - ReactDOM.render(React.createElement(getProvider(store, app, router)), container); + const ReactDOM = require('react-dom/client'); // eslint-disable-line + ReactDOM.createRoot(container).render(React.createElement(getProvider(store, app, router))); } function patchHistory(history) {