With the React Starter Kit, I add Material UI as follows:
npm install material-ui --save
and the following import to a component:
import RaisedButton from 'material-ui/lib/raised-button';
and:
<RaisedButton label="Default" />
I get the following error:
Warning: Material-UI: userAgent should be supplied in the muiTheme context for server-side rendering.
According to Material UI's documentation, it says I'd need to address three things:
- autoprefixer and the user agent
- process.env.NODE_ENV
What code should I put in and where exactly, specifically with the React Starter Kit?
P.S. this solution does not work for me :-/
If you are using KoaJS server you should install koa-useragent and then use this before server side rendering:
It worked for me !
The working (and the cleanest) solution for me is short and simple:
Example (from my test app):
This works for me. Add this to
server.js
:Then verify that you see multiple vendor prefixes used like in this screengrab showing
-webkit
and-ms
both being used:as you seen on MaterialUI documentation page
You need to provide the same user-agent for both server and browser contexts as you seen it in documentation, but, I strongly discourage you to provide a "all" user-agent, since you will serve a lot of unnecessary code to your end-user.
Instead you can easily follow MaterialUI doc and pass user-agent value contained in http request headers.
With an express or koa server
I just checked it has been added to the ReactStarterKit (not tested myself) in
src/server.js
This should fix it
Try adding
global.navigator = { userAgent: 'all' };
at the top of yourserver.js
file (Node.js entry point).