Skip to content

Commit

Permalink
fix(react): fix throw react-dom error in react-native (#3491)
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Oct 25, 2022
1 parent 3033416 commit 00141fe
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/react/src/shared/render.ts
@@ -1,16 +1,19 @@
import React from 'react'
import { createPortal } from 'react-dom'
import { globalThisPolyfill } from '@formily/shared'

const env = {
portalDOM: null,
ReactDOM: null,
}

export const render = (element: React.ReactElement) => {
if (globalThisPolyfill['document']) {
if (globalThisPolyfill.navigator?.product === 'ReactNative') return null
if (globalThisPolyfill.document) {
env.portalDOM =
env.portalDOM || globalThisPolyfill['document'].createElement('div')
return createPortal(element, env.portalDOM)
env.ReactDOM = env.ReactDOM || require('react-dom')
//eslint-disable-next-line
return env.ReactDOM.createPortal(element, env.portalDOM)
} else {
return React.createElement('template', {}, element)
}
Expand Down

0 comments on commit 00141fe

Please sign in to comment.