Skip to content

Commit

Permalink
avoid 'any' errors and make example clearer (#1957)
Browse files Browse the repository at this point in the history
  • Loading branch information
itayperry authored Jul 26, 2023
1 parent f11cc7f commit c5e7c30
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions docs/integrations/persisting-store-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -698,17 +698,28 @@ Let's say your state uses `Map` to handle a list of `transactions`,
then you can convert the Map into an Array in the storage prop:

```ts

interface BearState {
.
.
.
transactions: Map<any>
}

storage: {
getItem: (name) => {
const str = localStorage.getItem(name)
const str = localStorage.getItem(name);
if (!str) return null;
const { state } = JSON.parse(str);
return {
state: {
...JSON.parse(str).state,
transactions: new Map(JSON.parse(str).state.transactions),
...state,
transactions: new Map(state.transactions),
},
}
},
setItem: (name, newValue) => {
setItem: (name, newValue: StorageValue<BearState>) => {
// functions cannot be JSON encoded
const str = JSON.stringify({
state: {
...newValue.state,
Expand Down

1 comment on commit c5e7c30

@vercel
Copy link

@vercel vercel bot commented on c5e7c30 Jul 26, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.