React-native: React-Native doesn't allow importing of React-DOM

Created on 8 Jun 2016  路  6Comments  路  Source: facebook/react-native

The Issue

When you import the react-dom package in React-Native you're presented with the error page:

EventPluginRegistry: Cannot inject event plugin ordering more than once..

screen shot 2016-06-08 at 4 45 55 pm

While I understand that you cannot use anything from the React-DOM package I would assume that it doesn't start causing issues like these where the API's of React-DOM are not used.

Code to reproduce

//
// testing
//
import Foo from 'react-dom';

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 * @flow
 */

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View
} from 'react-native';

class bootstrap extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit index.ios.js
        </Text>
        <Text style={styles.instructions}>
          Press Cmd+R to reload,{'\n'}
          Cmd+D or shake for dev menu
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

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

Environment

  • React Native: 0.27
  • React-DOM: 15.1.x
  • Device: iOS
  • Platform: Mac OSX
Locked

Most helpful comment

We like to share some content written for the web, like svg graphs, in react native and it would be nice to render a web component inside a WebView like so: <WebView source={{body: ReactDOMServer.renderToString(<Graph />)}} />. When I try to import 'react-dom/server' I get this error.
It would off-course be even cooler if you could do something like this:
<WebView style={styles.container}> <body> <div>Hello world</div> </body> </WebView>

All 6 comments

What are you trying to achieve here?

Use react-native in React Native projects and react-dom is for Browsers.

@jiyinyiyong You can use separate files for native and web e.g. - .web.js and .native.js

@satya164 really, we've got so many extension names for JavaScript?

Closing this since the original author hasn't replied since a long time.

We like to share some content written for the web, like svg graphs, in react native and it would be nice to render a web component inside a WebView like so: <WebView source={{body: ReactDOMServer.renderToString(<Graph />)}} />. When I try to import 'react-dom/server' I get this error.
It would off-course be even cooler if you could do something like this:
<WebView style={styles.container}> <body> <div>Hello world</div> </body> </WebView>

Was this page helpful?
0 / 5 - 0 ratings