
React Collector help you to declere and manage a browser's storage.
Contents
Installation
Using npm
npm i --save react-collector
useCollector
useCollector allowing to get collector's props: storage, session & cookies
Prop | Description |
---|---|
storage | Allows you to access a Storage object for the Document's origin |
session | Use the sessions API to list, and restore, tabs and windows that have been closed while the browser has been running. |
cookies | Enables extensions to get and set cookies, and be notified when they change. |
uuid | Generate RFC-compliant UUIDs in JavaScript |
Actions
Action | Prop | Promise |
---|---|---|
add | key, payload | ActionResult |
get | T, key | T |
remove | key | ActionResult |
clear | -- | ActionResult |
Usage
Add Object to Collector
;
; storage.adduuid,user .then.catch session.adduuid,user; cookies.adduuid,user;
Add Primitive Type to Collector
storage.add"some-key","some-value"session.add1,true,cookies.add2,new Date
Get Object from Collector
storage.get"1f4a6aa4..." .then .catch;
Same for session and cookies
session.get"1f4a6aa4..." .then;
cookies.get"1f4a6aa4..." .then;
Get Primitive Type
storage.get"some-key".thensession.get1,true.then,cookies.get2,new Date.then;
Remove Element from Collector
storage.remove"1f4a6aa4..." .then // Same for session and cookiessession.remove"1f4a6aa4..." .then cookies.remove"1f4a6aa4..." .then
Clear Collector
cookies.clear.then //Same for storage and sessionsession.clear.then storage.clear.then
Full Example
Root Component
;; ;
Child component
;; ; ; ;
Todo
- Collector for indexedDB
- Collector for Web SQL