Skip to content

Instantly share code, notes, and snippets.

@smashercosmo
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smashercosmo/7bed813bd4ceb4dd2da9 to your computer and use it in GitHub Desktop.
Save smashercosmo/7bed813bd4ceb4dd2da9 to your computer and use it in GitHub Desktop.
import React from 'react';
import Router from 'react-router';
import routes from './routes';
import { createStore, combineReducers } from 'redux';
import { Provider } from 'react-redux';
import intlReducer from './intl/intl.reducer'
const app = document.getElementById('app');
/** initalState contains very complicated object with all translations */
const initialState = window._initialState;
const reducer = combineReducers({ intl: intlReducer });
const createStoreWithMiddleware = applyMiddleware(thunk)(createStore);
const store = createStoreWithMiddleware(reducer, initialState);
Router.run(routes, Router.HistoryLocation, (Handler) => {
React.render(
<Provider store={store}>
{() => <Handler />}
</Provider>, app);
});
import React from 'react';
export default class Header extends React.Component {
static propTypes = {
msg: React.PropTypes.object.isRequired
};
render() {
const {msg} = this.props;
return (
<header>
{/* initially there is no app.header, because reducer trigger dummy action with empty object as initial state */}
{msg.app.header}
</header>
);
}
}
/** i can't provide initial state, that has the same structure as translation object, because it's realy big and has multiple levels */
var initialState = {};
export default function intl(state = initialState) {
return state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment