Skip to content

Commit

Permalink
Readme: explain SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens authored Jul 24, 2017
1 parent f95d359 commit 9bac7e7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ For innerWidth/innerHeight, IE9 is sufficient. For the mediaqueries, this relies

**Object.assign() needs to be polyfilled if missing**. (It is probably already available, through your JSX build)

Server-side rendering
---

If you combine this with a library like https://github.com/hgoebl/mobile-detect.js, you can decide on the server whether to render for a phone or for desktop, or even for search bots.

To do this, derive e.g. `isPhone` and `isBot` from the `user-agent` header. Then initialize the Redux store, and dispatch the `mediaChanged` action:

```js
import {mediaChanged} from 'redux-mediaquery'
// ... create store
store.dispatch(mediaChanged({isServer: true, isPhone, isBot}))
```

Then, in your app, decide what to do with `isServer` and `isBot`. Finally, in the browser build, dispatch `isServer: false` after the first render (use the callback in `React.render(app, element, callback)` for that).

By updating `isServer` only after the first render, you make sure that React can re-use the pre-rendered content.

Changelog
---

Expand Down

0 comments on commit 9bac7e7

Please sign in to comment.