2.0.3 • Published 5 years ago

use-simple-storage v2.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

use Simple Storage

This is extremely simple state manager on hooks and context

Version Issues Downloads

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

MIT

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.3.4

5 years ago

1.3.3

5 years ago

1.3.2

5 years ago

1.3.1

5 years ago

1.3.0

5 years ago

1.2.9

5 years ago

1.2.8

5 years ago

1.2.7

5 years ago

1.2.6

5 years ago

1.2.5

5 years ago

1.2.4

5 years ago

1.2.3

5 years ago

0.1.2

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago