这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@jedelson-pagerduty
Copy link
Contributor

The solution described in #75 (comment) 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.

@polemius
Copy link
Owner

Could you please update documentation as well?

@jedelson-pagerduty
Copy link
Contributor Author

Could you please update documentation as well?

Done

Copy link
Owner

@polemius polemius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add mention of converter to Usage section

@jedelson-pagerduty
Copy link
Contributor Author

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.

@polemius
Copy link
Owner

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, // .... 
})

@jedelson-pagerduty
Copy link
Contributor Author

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?

@polemius
Copy link
Owner

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

@polemius polemius merged commit 227e2e4 into polemius:master Jun 23, 2023
@polemius
Copy link
Owner

Good job! Thank you!

@polemius
Copy link
Owner

Released in 5.0.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants