elgerlambert / redux-localstorage

Store enhancer that syncs (a subset) of your Redux store state to localstorage.
MIT License
1.32k stars 107 forks source link

Need more examples, thanks! #53

Closed ssr66994053 closed 8 years ago

ssr66994053 commented 8 years ago

sorry, i am new to this. after read the doc(v1.0), i am still don't know how use it in my project. could you please give me some more examples?

"dependencies": { "material-ui": "^0.15.3", "radium": "^0.18.1", "react": "^15.2.0", "react-dom": "^15.2.0", "react-redux": "^4.4.5", "react-router": "^2.5.2", "react-router-redux": "^4.0.5", "react-tap-event-plugin": "^1.0.0", "redux": "^3.5.2", "redux-localstorage": "^1.0.0-rc5", "redux-localstorage-filter": "^0.1.1", "redux-logger": "^2.6.1", "redux-saga": "^0.10.5" }

ssr66994053 commented 8 years ago

i got it! the key in filter must be the state map to props. like below:

const storage = compose(
  filter('counter')
)(adapter(window.localStorage));

....

const mapStateToProps = (state) => ({
  counter: state.counter,
})

const enhancers = compose(
  /* middlewares */
  persistState(storage, 'my-storage-key')
)

then in the local storage will have this

my-storage-key : {"counter": 0}
ghost commented 7 years ago

Hello, Have you ever encountered this problem?

 const logger = createLogger({ stateTransformer });
    const middlewares = [
        thunkMiddleware,
        sagaMiddleware,
        logger,
        routerMiddleware(createHistory()),
    ];

    const reducer = compose(
        mergePersistedState()
    )(createReducer);

    const storage = compose(
        filter('app')
    )(adapter(window.localStorage));

    const enhancer = compose(
        applyMiddleware(...middlewares),
        persistState(storage),
        devtools,
    );

8o9 ozdg bou txfx yg

    "immutable": "^3.8.1",
    "react": "^15.2.1",
    "react-dom": "^15.2.1",
    "react-redux": "^4.4.5",
    "react-router": "^2.8.1",
    "react-router-redux": "^4.0.6",
    "redux": "^3.5.2",
    "redux-actions": "^0.12.0",
    "redux-immutable": "^3.0.8",
    "redux-logger": "^2.6.1",
    "redux-saga": "^0.12.0",
    "redux-thunk": "^2.1.0",
    "reselect": "^2.5.4",