Martin Sojka
Martin Sojka

Reputation: 533

ReactDOMServer is not defined

I'm using pre-built browser builds of React and ReactDOM v15 from here since I can't use npm in a given project.

I need to use renderToString from the react-dom/server but I'm getting ReactDOMServer is not defined error.

React and ReactDOM are fine. Any idea how I can access ReactDOMServer?

Upvotes: 3

Views: 5968

Answers (3)

sapy
sapy

Reputation: 9584

Cause you haven't imported it. Add this

import ReactDOMServer from 'react-dom/server';

If react-dom/server not found then you need to npm install it

npm install react react-dom

Upvotes: 4

Jesse
Jesse

Reputation: 386

Actually, after running into this issue myself and trying to find ReactDOMServer somewhere, I almost gave up and was looking for the source directly and about to Browserfiy when like 10 answers down in Google I saw the cdnjs libaries and lo and behold:

https://cdnjs.com/libraries/react/

https://cdnjs.cloudflare.com/ajax/libs/react/15.4.0/react-dom-server.min.js

So I guess they have it built there, and so there you go, you can include it wherever you like, like JSBin as I'm doing.

Upvotes: 1

Einstein
Einstein

Reputation: 441

In my bundles file I had to import:

//= require react-dom/static/react-dom-server

Then I was able to import ReactDOMServer from react-dom/server without a problem.

Upvotes: 0

Related Questions