polemius / recoil-persist

Package for recoil state manager to persist and rehydrate store
https://polemius.dev/recoil-persist/
MIT License
353 stars 39 forks source link

ability to set multiple value for single key #38

Closed skyrocketeer closed 3 years ago

skyrocketeer commented 3 years ago

Can you provide a way to set the key instead of hard coding value recoil-persist?

polemius commented 3 years ago

You can change the key using parameters like in this example:

const { persistAtom } = recoilPersist({
  key: 'recoil-persist', // this key is using to store data in local storage
})

https://github.com/polemius/recoil-persist#usage

skyrocketeer commented 3 years ago

I have problems for setting multiple values for one single custom key

Example:

const { persistAtom } = recoilPersist({ key: 'mykey' })

export const isLoggedIn = atom({
  key: "isLoggedIn",
  default: false,
  effects_UNSTABLE: [persistAtom],
})

export const userData = atom({
  key: "userProfile",
  default: null,
  effects_UNSTABLE: [persistAtom],
})

In use: const [isAuth, setAuth] = useRecoilState(isLoggedIn) const [user, setUser] = useRecoilState(userData)

Unfortunately, when I do setUser(value) and setAuth(true) it only updates the first value being set

polemius commented 3 years ago

I have added to demo button to update multiple atoms from one function. I can see that it works. Please check it out https://polemius.dev/recoil-persist/

Also please take a look at demo page source code: https://github.com/polemius/recoil-persist/blob/master/test/demo/index.js

Let me know if you find some problems.

skyrocketeer commented 3 years ago

I have added to demo button to update multiple atoms from one function. I can see that it works. Please check it out https://polemius.dev/recoil-persist/

Also please take a look at demo page source code: https://github.com/polemius/recoil-persist/blob/master/test/demo/index.js

Let me know if you find some problems.

I tried again and it worked like a champ. Tks alot for your kind support