use-simple-storage v2.0.3
use Simple Storage
This is extremely simple state manager on hooks and context
TypeScript support included!
Link for npm package
https://www.npmjs.com/package/use-simple-storage
Installation
yarn add use-simple-storage
Usage
Wrap your application with StorageManager
Please do Initial Storage as object :)
import { StorageManager } from 'use-simple-storage';
const INITIAL_STORAGE = {};
export const App = () => (
return (
<StorageManager initialStorage={INITIAL_STORAGE}>
{children}
</StorageManager>
);
);
Usage inside your application
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 remember
Please do destructuring from
useSimpleStorage();
Because it's a hook and you can get errors later if you call that in callback etc.
Actions
setPart(partitionName, data)
Creates partition in global storage
getPart(partitionName)
Returns partition from global storage
getStorage()
Returns global storage
setPartToLS(partitionName, data)
Creates partition in local storage of your browser
getPartFromLS(partitionName)
Returns partition from local storage of your browser
deletePart(partitionName)
Erasing part from global storage
deletePartFromLS(partitionName)
Erasing part from local storage
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago