Hands-on practice for this lecture. Work through the exercises and quizzes to reinforce what you've learned.
Exercise 1 of 1
Live editor: implement a useLocalStorage custom hook that wraps useState and syncs to localStorage — so preferences survive page refreshes.
Task
Implement useLocalStorage(key, initialValue) — a custom hook that works like useState but persists its value to localStorage.
localStorage.getItem(key) (fall back to initialValue if absent)[value, setValue] — same API as useStatelocalStorage.setItem in a useEffect whenever the value changesJSON.parse / JSON.stringify to support any serializable value