easy-peasy icon indicating copy to clipboard operation
easy-peasy copied to clipboard

Possible to change LocalStorage Item name?

Open sikandarchishty opened this issue 4 years ago • 6 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 :)

sikandarchishty avatar Sep 01 '21 18:09 sikandarchishty

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

viczaca avatar Sep 07 '21 17:09 viczaca

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

sikandarchishty avatar Sep 23 '21 19:09 sikandarchishty

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 avatar Oct 13 '21 14:10 ctrlplusb

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

viczaca avatar Oct 14 '21 10:10 viczaca

How is "persist" working in react-native?

LucaGabi avatar Dec 27 '21 20:12 LucaGabi

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.

musabgulfam avatar Jan 20 '23 15:01 musabgulfam