1

We are using react-rails gem v1.10.0 to incorporate react in our rails app. The renderToString method is used in order to create a popover effect as such

popover = React.createElement Popover, user: @props.user, avatar: @imageSrc()
React.renderToString(popover)

however I am getting a Uncaught TypeError: React.renderToString is not a function

This used to work fine but I think I'm getting the error now because renderToString is under RenderDOMServer. Unfortunately, when I try

ReactDOMServer.renderToString(element)

I get an Uncaught ReferenceError: ReactDOMServer is not defined

How do I get ReactDOMServer in the application so I can use the renderToString method?

stcho
  • 1,909
  • 3
  • 28
  • 45
  • you have to also include ReactDOMServer in the rails config. I think it should go here `app/assets/vendor/` per the docs https://github.com/reactjs/react-rails/blob/master/VERSIONS.md#bundled-versions – Brian McCall Mar 14 '17 at 18:19
  • @BrianMcCall I tried adding it from https://cdnjs.com/libraries/react/ however I get a different error within the react-dom-server.min.js file – stcho Mar 14 '17 at 18:45
  • what does your rails config look like? – Brian McCall Mar 14 '17 at 19:32
  • We used `renderToString` only to render small things like links with interpolated props. We simply replaced them with CoffeeScript interpolation. E.g. `foo = """#{theText}"""` – Henrik N Apr 25 '17 at 09:39

0 Answers0