Skip to content

Commit

Permalink
fix: 兼容在 React 19 环境下的 Toast 组件
Browse files Browse the repository at this point in the history
  • Loading branch information
lujun2 committed Nov 1, 2024
1 parent e667fa9 commit c88b4cb
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/utils/render.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ReactElement } from 'react'
import * as ReactDOM from 'react-dom'
import type { Root } from 'react-dom/client'
import { type Root, createRoot as createClientRoot } from 'react-dom/client'

// 移植自rc-util: https://github.com/react-component/util/blob/master/src/React/render.ts

Expand All @@ -21,9 +21,9 @@ const { version, render: reactRender, unmountComponentAtNode } = fullClone
let createRoot: CreateRoot
try {
const mainVersion = Number((version || '').split('.')[0])
if (mainVersion >= 18 && fullClone.createRoot) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
createRoot = fullClone.createRoot
const createReactRoot = createClientRoot || fullClone.createRoot
if (mainVersion >= 18 && createReactRoot) {
createRoot = createReactRoot
}
} catch (e) {
// Do nothing;
Expand Down

0 comments on commit c88b4cb

Please sign in to comment.