difficulty | training | chapter | tags |
---|---|---|---|
1 |
true |
Chapter 7: Challenge Roundup |
vue |
In this challenge, you'll create a custom useLocalStorage
composable.
- The composable should accept the following parameters:
key
- a string that represents the key in localStorage, requireddefaultValue
- the initial value to be stored in localStorage
- The composable should return a ref called value that holds the value from localStorage
- The returned value should be updated when the related data in localStorage is updated
- The data in localStorage should be updated when the ref value is updated
- The composable does NOT have so support complex data types like objects (just strings is fine)
💡 HINT: You can use the following browser API to listen for changes in local storage window.addEventListener("storage", (event) => { if(event.key === key){ /_ Do stuff with event.newValue _/ }});