fire-hydrant

hydration and serialization of state, targeted at Redux SSR.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
fire-hydrant
700.16.38 years ago8 years agoMinified + gzip package size for fire-hydrant in KB

Readme

fire-hydrant
lightweight hydration and serialization of state, targeted at Redux Server Side Rendering and ImmutableJS NPM dependencies

Install

npm i -S fire-hydrant

Documentation

Functions used to store state objects, partial immutables, and full immutables to strings and restore them back to their original state.

react-router and react-router-redux with async routes example

configureStore.js

```js import { createStore, applyMiddleware } from 'redux' import { routerMiddleware } from 'react-router-redux' import { combineReducers } from 'redux' import as reducers from '../reducers' export default function configureStore(history, initialState) { const reducer = combineReducers(reducers) const enhancer = applyMiddleware( routerMiddleware(history) ) return createStore(reducer, initialState, enhancer) } ```

createRouter.js

Plug this router into your server.use() ```jsx import React from 'react' import Router from 'router' import Immutable from 'immutable' import { Provider } from 'react-redux' import { createMemoryHistory, match, RouterContext } from 'react-router' import { syncHistoryWithStore } from 'react-router-redux' import { serialize, createInitialState } from 'fire-hydrant' / Routes can be direct server defined routes or a webpack bundle / import routes from './routes' const InitialState = ({ state }) => { const serialized = serialize(state, { Immutable }) const html = window.__initialState__ = ${serialized} return