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

Possible to change LocalStorage Item name? #696

Open
sikandarchishty opened this issue Sep 1, 2021 · 6 comments
Open

Possible to change LocalStorage Item name? #696

sikandarchishty opened this issue Sep 1, 2021 · 6 comments

Comments

@sikandarchishty
Copy link

Hi,
is it possible to rename my easy-peasy persist localStorage name (key name)?

Currently it stores something like this :
image

Thanks in advance :)

@viczaca
Copy link

viczaca commented Sep 7, 2021

I guess this is not documented here.
There is a second parameter in createStore where you can set the name.

const store = createStore(model, {
  name: "THE_NAME_YOU_WANT",
})

@sikandarchishty
Copy link
Author

Hi @viczaca,

thank you for your response.

I have tried but doesn't work for me. I am also using persist.

here's what doesn't work

const store = createStore(
  persist(
    {
      MainData: {
        defaults: {
          name: "",
          titel: "",
          isNew: false,
          isOn: false,
        },
      },
    },
    { storage: "localStorage", name: "new name" } // doesn't work
  ),
  {
    name: "new name", // this also doesn't work
  }
);

@ctrlplusb
Copy link
Owner

I believe the intention of the name was to distinguish store instances within the Redux Devtools - however, I believe there are still issues with this when recreating stores with the same name.

It's an interesting angle to use the name as the mechanism of persisting the store. I'll look into this.

@viczaca
Copy link

viczaca commented Oct 14, 2021

@ctrlplusb I thought this was already a feature.

This is my code. I'm using localforage as my persistent storage.

const store = createStore<Model>(persist(model, { storage: localforage }), {
  name: 'MY_STORE_NAME',
});

And this is the result.
image

Maybe the name is related to localforage and not easy-peasy.

BTW, I'm using easy-peasy 5.0.4.

@LucaGabi
Copy link

How is "persist" working in react-native?

@ctrlplusb ctrlplusb moved this to 📋 Backlog in Easy Peasy Sep 16, 2022
@musabgulfam
Copy link

musabgulfam commented Jan 20, 2023

How is "persist" working in react-native?

You will have to use AsyncStorage from @react-native-async-storage/async-storage instead of default storage engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 📋 Backlog
Development

No branches or pull requests

5 participants