Skip to content
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

useStorage: difference between Object.keys(rawValue) and Object.keys(rawInit) #1954

Closed
7 tasks done
haoval opened this issue Jul 19, 2022 · 3 comments · Fixed by #1957
Closed
7 tasks done

useStorage: difference between Object.keys(rawValue) and Object.keys(rawInit) #1954

haoval opened this issue Jul 19, 2022 · 3 comments · Fixed by #1957
Labels
enhancement New feature or request pr welcome

Comments

@haoval
Copy link

haoval commented Jul 19, 2022

Describe the bug

if an object exists in localStorage with given key:

test: {
  a:1
}

oops:

const testState = useLocalStorage('test', {
  a: 1,
  b: 2,
})
console.log(testState.value.b) // returns undefined

Reproduction

dev

System Info

--npmPackages {
  "@vueuse/core": "^8.9.3"
}

Used Package Manager

pnpm

Validations

@antfu
Copy link
Member

antfu commented Jul 19, 2022

Yeah, currently initValue only applies when the stored value is undefined. I think we could introduce an option to deep merge the initialValue. PR welcome

@antfu antfu added enhancement New feature or request pr welcome labels Jul 19, 2022
@lumdzeehol
Copy link
Contributor

Yeah, currently initValue only applies when the stored value is undefined. I think we could introduce an option to deep merge the initialValue. PR welcome

useStorage locates in @vueuse/core, so I think it's better to implement a lite deepmerge function internally instead of introducing lib likes deepmerge

@antfu
Copy link
Member

antfu commented Jul 19, 2022

Yes #1957 allows it to be a function to provide custom merge logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pr welcome
Projects
None yet
3 participants