0

I have set up for Server Side rendering. However the code in server.js calling store.getstate() only gets my default initial state and not the state the client is. How can I fix this?

Server.js: http://pastebin.com/u31cqaUh

Configurestore: http://pastebin.com/7FXV6NDS

Root.js:

import React, {Component} from 'react';
import {Provider} from 'react-redux';
import configureStore from './store/configureStore';
import {Router, Route, hashHistory, browserHistory} from 'react-router';
import { syncHistoryWithStore, routerReducer } from 'react-router-redux';
import Routes from '../routes';

const store = configureStore(window.__INITIAL_STATE__);
delete window.__INITIAL_STATE__;
const history = syncHistoryWithStore(browserHistory, store)

export default class Root extends Component {
    render() {
        return (
            <Provider store={store}>
                <Router history={history} routes={Routes}>
                </Router>
            </Provider>
        )
    }
}
marti
  • 173
  • 4
  • 11
  • when and where do you ever pass the client state to the server? – Brandon Jul 01 '16 at 18:28
  • @Brandon uhhm... I thought routerreducer in Root.js does it? – marti Jul 01 '16 at 18:32
  • no, redux is very simple combination of functions, there is no data sending fetching mechanism behind it.. – webdeb Jul 01 '16 at 18:36
  • How can I pass it then? How is it generally done? – marti Jul 01 '16 at 18:36
  • You have many options, you could store the last state in the browser, for example with `localStorage` – webdeb Jul 01 '16 at 18:42
  • Client must find a way to send the state to the server with the request. – Brandon Jul 01 '16 at 18:44
  • Generally you have an API on the server, where you can send data too.. If you need it on the server. You would need to serialize your state (`JSON.stringify(store.getState())` to a string and send it to the server – webdeb Jul 01 '16 at 18:45
  • Is there any difference in just storing it in localstorage and recreating it in client vs passing it to server and setting it in window again? – marti Jul 01 '16 at 18:55
  • http://stackoverflow.com/questions/33924429/what-are-your-best-practices-for-preloading-initialstate-in-your-redux-apps Here it seems they arent passing the state to server. – marti Jul 02 '16 at 08:22

0 Answers0