Closed jedelson-pagerduty closed 1 year ago
Could you please update documentation as well?
Could you please update documentation as well?
Done
Please add mention of converter to Usage section
I assume in the Usage section it makes sense to show the default but please let me know if you think something else should go there.
I assume in the Usage section it makes sense to show the default but please let me know if you think something else should go there.
I thought maybe we could show in Usage section all options like:
import { recoilPersist } from 'recoil-persist'
const { persistAtom } = recoilPersist({
key: 'recoil-persist', // this key is using to store data in local storage
storage: localStorage, // configurate which storage will be used to store the data
converter: JSON, // ....
})
Yeah, what I put there is
import { recoilPersist } from 'recoil-persist'
const { persistAtom } = recoilPersist({
key: 'recoil-persist', // this key is using to store data in local storage
storage: localStorage, // configurate which storage will be used to store the data
converter: { // configurate how values will be serialized/deserialized in storage
parse: (value) => JSON.parse,
stringify: (value) => JSON.stringify
}
})
Although converter: JSON
would be semantically the same thing, I think it's useful to show both functions. WDYT?
converter: { // configurate how values will be serialized/deserialized in storage
parse: (value) => JSON.parse(value),
stringify: (value) => JSON.stringify(value)
}
you need to pass values to function
Good job! Thank you!
Released in 5.0.0 🚀
The solution described in https://github.com/polemius/recoil-persist/issues/75#issuecomment-1474769954 doesn't work (at least for my use case) because
setItem
accepts a string whereas I (and I suspect @tpict) need to control how stringify/parse actually work.