Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add localstorage sync #2

Open
kimgysen opened this issue May 24, 2019 · 1 comment
Open

Add localstorage sync #2

kimgysen opened this issue May 24, 2019 · 1 comment

Comments

@kimgysen
Copy link

Cool project, I'm currently using this for a prototype!
Localstorage can be added by :

    import { DEFAULT_STORE_NAME, DEFAULT_LOCALSTORAGE_NAME } from 'c/constants'
    @api localstorgeName = DEFAULT_LOCALSTORAGE_NAME;
    @api persistedState = localStorage.getItem(DEFAULT_LOCALSTORAGE_NAME) 
      ? JSON.parse(localStorage.getItem(DEFAULT_LOCALSTORAGE_NAME)) 
      : {};

    async connectedCallback() {
        const {
            storeName,
            reducers,
            persistedState,
            useCombineReducers,
            useThunk,
            useLogger,
            secondary,
        } = this;

        const store = createStore(rootReducer, persistedState, enhancer);
        store.subscribe(()=>{
          localStorage.setItem('reduxState', JSON.stringify(store.getState()));
        });

Although it works, there is this strange issue that localStorage stores the redux state with key '1' intead of the defined DEFAULT_LOCALSTORAGE_NAME.
Any idea why is that?

@GTCarmona
Copy link

Hello! I am having the same issue, looked around and no answer. By any chance you figure why would the key be replaced by 1 instead of the given name?

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants