
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
complete-react-storage
Advanced tools
Hook para sincronizar estado con localStorage/sessionStorage con TTL y cross-tab
Hook para sincronizar estado con localStorage / sessionStorage (TTL, cross‑tab).
npm install complete-react-storage
# o
pnpm add complete-react-storage
# o
yarn add complete-react-storage
import { useStorage } from 'complete-react-storage';
function MyComponent() {
const [count, setCount, removeCount] = useStorage('counter', 0);
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(c => c + 1)}>+</button>
<button onClick={() => setCount(c => c - 1)}>-</button>
<button onClick={removeCount}>Reset</button>
</div>
);
}
useStorage(key, initial, options?)Retorna una tupla [value, setValue, removeValue]:
value: Valor actual del storagesetValue: Función para actualizar el valor (acepta función callback)removeValue: Función para eliminar del storage y resetear al valor inicial| Parámetro | Tipo | Descripción |
|---|---|---|
key | string | Clave única para el storage |
initial | T | Valor inicial si no existe en storage |
options | UseStorageOptions<T> | Opciones de configuración |
| Propiedad | Tipo | Default | Descripción |
|---|---|---|---|
area | "local" | "session" | "local" | Tipo de storage a usar |
json | boolean | true | Si usar JSON.stringify/parse |
ttl | number | undefined | Tiempo de vida en milisegundos |
crossTab | boolean | true | Sincronización entre pestañas |
migrate | (raw: unknown) => T | undefined | Función de migración de datos |
const [token, setToken, clearToken] = useStorage('auth-token', null, {
ttl: 1000 * 60 * 60 * 24, // 24 horas
area: 'session'
});
// El token se elimina automáticamente después de 24 horas
interface User {
id: number;
name: string;
email: string;
}
const [user, setUser, clearUser] = useStorage<User | null>('user', null, {
crossTab: true,
area: 'local'
});
// Actualizar usuario
setUser(current => current ? { ...current, name: 'Nuevo nombre' } : null);
const [settings, setSettings] = useStorage('app-settings', { theme: 'light' }, {
migrate: (raw) => {
// Migrar datos de versiones anteriores
if (typeof raw === 'string') {
return { theme: raw }; // v1 solo guardaba el tema como string
}
return raw as any;
}
});
const [sessionId, setSessionId] = useStorage('session', '', {
area: 'session',
json: false, // Almacenar como string plano
crossTab: false
});
const [cache, setCache, clearCache] = useStorage('api-cache', {}, {
area: 'local',
ttl: 1000 * 60 * 5, // 5 minutos
crossTab: true,
migrate: (raw) => {
// Limpiar cache legacy
if (!raw || typeof raw !== 'object') return {};
return raw;
}
});
FAQs
Hook para sincronizar estado con localStorage/sessionStorage con TTL y cross-tab
We found that complete-react-storage demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.