react-native icon indicating copy to clipboard operation
react-native copied to clipboard

is it possible to run `renderToStaticMarkup` in react-native

Open gorangajic opened this issue 11 years ago • 5 comments

I have tried running renderToStaticMarkup in react-native but it's complaining that two versions of react are running.

Invariant Violation: EventPluginRegistry: Cannot inject event plugin ordering more than once. You are likely trying to load more than one copy of React.

I have also tried to load local ReactDomServer from react-native module but error is the same

import { renderToStaticMarkup } from 'react-native/node_modules/react-tools/src/renderers/dom/ReactDOMServer'

Is it possible something like that in react-native, or I need to create new renderer? I just want to get jsx/xml that is passed to my Component. I will also be happy with json output, something like this

componentDidMount() {
   var json = renderToJson(this.props.children);
}

Thanks

gorangajic avatar Nov 03 '15 10:11 gorangajic

Rendering to markup is a feature of react-dom, not react nor react-native. What are you trying to do? If you want to render to divs and spans you should write/find a project (there are some out there) that reimplements View.js, ScrollView.js, etc and renders divs/spans.

ide avatar Nov 03 '15 19:11 ide

@ide I just want to find out what is passed to this.props.children. Using react-dom I was able to convert this.props.children to xml and then parse xml to javascript object.

btw I was able to hack quick solution https://github.com/gorangajic/react-render-to-json

gorangajic avatar Nov 03 '15 21:11 gorangajic

Now react has been de-vendored, any hope of being able to use react-dom in react-native?

import ReactDOMServer from 'react-dom/server';

still yields: image

cancan101 avatar Jan 20 '16 19:01 cancan101

@cancan101 did you have any luck since your post? I was hoping to use react-dom to render html so that it could be passed into the RN webview.

jgibbons avatar Feb 16 '16 21:02 jgibbons

+1 @ide my usecase is for quick visualization and debugging output of a complex module with nested components. Btw: The quick toJson solution @gorangajic mentioned seems to no longer play nice with Babel: http://screencast.com/t/y6fAV3OIJg

andresn avatar Apr 03 '16 19:04 andresn