Closed skyrocketeer closed 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
})
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
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 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
Can you provide a way to set the key instead of hard coding value
recoil-persist
?