ctrlplusb / easy-peasy

Vegetarian friendly state for React

Home Page:https://easy-peasy.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible to change LocalStorage Item name?

sikandarchishty opened this issue · comments

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

Currently it stores something like this :
image

Thanks in advance :)

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",
})

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
  }
);

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.

@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.

How is "persist" working in react-native?

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.