-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bug]: localStorageKey option has no effect #49
Comments
I tried to replicate with react-example. When refresh page with F5, the toolbar option is reset, but the localStorage key and also addon state is as
{
"grid": {
"value": false
},
"responsive": {
"value": false
},
"outline": {
"value": true
},
"maximize": {
"value": false
},
"theme": {
"value": "auto"
}
}
|
I tried to fix the issue, but there are multiple approaches. Use zustand build in persisting store dataDocs: I got it working wrapping import { createJSONStorage, persist } from 'zustand/middleware'
import { shallow } from 'zustand/shallow'
import { createWithEqualityFn } from 'zustand/traditional'
export const useStoryLiteStore = createWithEqualityFn<StoryLiteStore>()(
persist(
set => {
const createStoryMap = (moduleMap: StoryModuleMap): StoryMap => {
...
}
return {
...defaultState,
...
}
},
{
name: 'storylite.parameters',
partialize: state => state.parameters,
storage: createJSONStorage(() => localStorage),
},
),
shallow,
) The Object stored in localStorage will be wrapped with {
"state": {
"grid": {
"value": false
},
"responsive": {
"value": false
},
"outline": {
"value": false
},
"maximize": {
"value": false
},
"theme": {
"value": "auto"
}
},
"version": 0
} When using this approach, the custom In addition initalize state with propsLike described in the Docs, I think this would be easiest way to implement. Split state into multiple objectsFor me it makes sense to split state into multiple objects, only apply There might be more approaches, but I think to use the build in zustand Would be great if you take care on the issue and hope this info helps. I better get into the SCSS 😁 |
Thank you for the investigation @jrson83 . We can also have multiple stores, let's see... and maybe it's time for me to add proper tests :D I will take care of this |
Describe the bug
When setting the
localStorageKey
, to a different value than the default, the UI options are not persisted and the default key is still used in the local storage.Reproduction
The text was updated successfully, but these errors were encountered: