# useLocalStorage
A custom hook to interact with the browser's `localStorage` API.
It provides a simple way to manage persistent state, including support for serialization and deserialization of complex values.
## Usage
```tsx
import { useLocalStorage } from '@gilbarbara/hooks';
function Component() {
const [user, setUser, removeUser] = useLocalStorage('user', { name: 'John Doe', age: 30 });
return (
User: {JSON.stringify(user)}
);
}
```
## Reference
```typescript
type UseLocalStorageOptions =
| {
raw: true;
}
| {
deserializer: (value: string) => TValue;
raw: false;
serializer: (value: TValue) => string;
};
export type UseLocalStorageResult = [
value: TValue | undefined,
setValue: Dispatch>,
remove: () => void,
];
useLocalStorage(key, initialValue?: TValue, options?: UseLocalStorageOptions): UseLocalStorageResult;
```
- key — localStorage key to manage.
- initialValue — the initial value to set, if the value in localStorage is empty.
- options.raw — if set to true, the hook will not attempt to JSON serialize stored values.
- options.serializer — custom serializer (defaults to JSON.stringify)
- options.deserializer — custom deserializer (defaults to JSON.parse)