Skip to content
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

Using react-native-web with ReactDOM.createPortal #1765

Closed
timothylui opened this issue Oct 12, 2020 · 5 comments
Closed

Using react-native-web with ReactDOM.createPortal #1765

timothylui opened this issue Oct 12, 2020 · 5 comments
Labels
has: pr Subject of a pull request

Comments

@timothylui
Copy link

Is your feature request related to a problem? Please describe.
Hi, I'm creating an electron app with multiple windows and we're currently using window.open and then using ReactDOM.createPortal to set the document body.

This works great if you're using straight react, but when we're trying to use react-native it is missing the styles.

This also happens when trying to do the same thing in the browser, so isn't related to electron.

Describe a solution you'd like

As ReactDOM.createPortal creates a section of the dom, a way to set up the page so that react-native-web components render correctly. Alternatively, if this works already, a working example would be great.

Describe alternatives you've considered

Writing it in pure react but that means we can't reuse the components

@necolas
Copy link
Owner

necolas commented Oct 13, 2020

Shouldn't you be using render rather than createPortal?

Multiple document roots isn't supported at the moment

@wjps
Copy link

wjps commented Oct 13, 2020

I've been fighting with the same problem so would also be interested in the best way to get in working. Would something like react-gateway work?

I'm not sure how I'd use render to solve the problem though.

@nandorojo
Copy link
Contributor

I've been looking for something like react-gateway too. Now that RNW supports modals, I think a modal-based solution would work for popovers. I came across SteffeyDev/react-native-popover-view#82 today, so I'll see if that works with the new RNW.

@wjps
Copy link

wjps commented Oct 14, 2020

Ok, I've managed to get things working by doing

import App from '../App';
import { AppRegistry } from 'react-native-web';

AppRegistry.registerComponent('App', () => App);

then rendering the css into the new window with 
    ...
    render () {
    ...
       return (
          ...
          { AppRegistry.getApplication('App', {}).getStyleElement() }
          ...
       )
   }

Not sure if that's a valid way to do things but it seems to work.

@necolas necolas added this to the 0.18: StyleSheet milestone Mar 1, 2022
@necolas necolas added the has: pr Subject of a pull request label Mar 2, 2022
@necolas
Copy link
Owner

necolas commented Jun 10, 2022

Multiple roots should now be supported in 0.18

@necolas necolas closed this as completed Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: pr Subject of a pull request
Projects
None yet
Development

No branches or pull requests

4 participants