Frontendx
Frontendx
README.md
SOLUTION.md
main.tsxentry
App.tsx
App.css
index.html
vite.config.ts
Plugins
Installed
react@^19.2.0
react-dom@^19.2.0
Editor
Custom Hooks Pattern
Description
Create a custom hook useLocalStorage that syncs state with localStorage, allowing data to persist across page reloads.
Example 1:
const [value, setValue] = useLocalStorage('key', 'default');
// Value is synced with localStorage
// Updates to value automatically persist
Example 2:
// On first render, reads from localStorage
// When value changes, writes to localStorage
// When localStorage is empty, uses default value
Constraints
- Create a
useLocalStoragecustom hook - Hook should accept a key and default value
- Return a stateful value and setter function
- Sync state with localStorage on changes
- Handle initial load from localStorage
- Clean up properly (optional for this exercise)
Custom hooks are functions that use React hooks
Preview
Terminal
Test Results
Custom Hooks Pattern
Create a custom hook to encapsulate and reuse stateful component logic.