React Local Storage
A stateful react hook for browser storage.
Why?
Install
npm install @webcored/react-local-storage
Usage
component.jsx
import { useLocalStorage } from "@webcored/react-local-storage";
const [user, userStorage] = useLocalStorage('user');
....
typescript
const [user, userStorage] = useLocalStorage<User>('user');
....
update
userStorage.update({ ...user, name: 'new name' });
remove
userStorage.remove();
reset
Reset's to the default value provided in the key config
userStorage.reset();
Sample app
typescript
Configurations
import React from 'react';
import { user } from './storages/user';
import { storageConfig } from "@webcored/react-local-storage";
storageConfig({
namespace: 'app',
delimiter: '/'
react: React
storages: {
user
}
}
…