astoilkov / use-local-storage-state

React hook that persists data in localStorage
MIT License
1.09k stars 39 forks source link

Migrating from `createLocalStorageStateHook` #64

Closed FarazPatankar closed 1 year ago

FarazPatankar commented 1 year ago

Hey, so I am seeing a few usages of createLocalStorageStateHook in our codebase and I noticed the latest version does not have this function?

I also went through the releases and didn't see a mention of it being removed as a breaking change. Could I get any pointers on how to migrate the existing usages?

FarazPatankar commented 1 year ago

I think I figured it out. Basically went from:

export const useParticles = createLocalStorageStateHook(
  "@railway/particles",
  false,
);

const [showParticles, setShowParticles] = useParticles();

to:

export const useParticles = () =>
  useLocalStorageState("@railway/particles", {
    defaultValue: false,
  });

// Usage remains the same
const [showParticles, setShowParticles] = useParticles();

Leaving it open so you can correct me if I am wrong. 😄

astoilkov commented 1 year ago

Hey, good to hear you are upgrading.

Yes, you nailed it. That's precisely the correct usage of the new API.

Yeah, I haven't mentioned the upgrade steps. Sorry about that. Still learning to do open-source.

Let me know if you stumble on anything else so I can help.

FarazPatankar commented 1 year ago

Everything else seems fine, we use the lib pretty heavily, great work! 💚

astoilkov commented 1 year ago