This is extremely simple state manager on hooks and context
https://www.npmjs.com/package/use-simple-storage
yarn add use-simple-storage
import { StorageManager } from 'use-simple-storage';
const INITIAL_STORAGE = {};
export const App = () => (
return (
<StorageManager initialStorage={INITIAL_STORAGE}>
{children}
</StorageManager>
);
);
import { useSimpleStorage } from 'use-simple-storage';
export const Example = () => (
const { setPart, getPart, getStorage, getPartFromLS, setPartToLS } = useSimpleStorage();
const user = {
name: 'John',
age: 12,
};
return (
<button type="button" onClick={() => setPart('user', user)} />
);
);
Done! Now you can use your application with extremely simple and easy state manager!
Please do destructuring from
useSimpleStorage();
Because it's a hook and you can get errors later if you call that in callback etc.
Creates partition in global storage
Returns partition from global storage
Returns global storage
Creates partition in local storage of your browser
Returns partition from local storage of your browser
Erasing part from global storage
Erasing part from local storage
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.