useStorage
🕋 React hook using local storage on SSR, CSR, and React Native apps
⚠ This is under active development. Stay tuned ⚠
⚠ This is under active development. Stay tuned ⚠
npm i use-react-storage
Features
- SSR (server side rendering) support
- TypeScript support
- 1 dependency (use-ssr)
Usage
Object Destructuring
import useStorage useLocalStorage useCookie // NOT IMPLEMENTED YET useSessionStorage // NOT IMPLEMENTED YET useNativeStorage // NOT IMPLEMENTED YET = 'use-react-storage' const App = // SSR (server side rendered): cookies // CSR (client side rendered): localStorage, unless using `useSessionStorage` // Native (react native): AsyncStorage const someKey1 someKey2 // can grab the `items/keys` right out set // updates/sets the specified items remove // removes the specified items clear // clears the storage flushGetRequests // NOT IMPLEMENTED YET (Native Only) allItems // NOT IMPLEMENTED YET errors // NOT IMPLEMENTED YET = // usages for `set` // for multi setting items // for setting individual item // usages for `remove` // would remove both items from storage // OR const someKey1 someKey2 set remove clear flushGetRequests // NOT IMPLEMENTED YET (Native Only) allItems // NOT IMPLEMENTED YET errors // NOT IMPLEMENTED YET } = }
Array Destructuring
const App = { const token setToken removeToken = // used like // OR const items set remove = const item1 item2 = items // used like }
By default this will determine where your app is and decide which storage to use.
If your app is SSR (server side rendered), a flag will be set and it will default to using Cookies
for storage
If your app is CSR (client side rendered), in the browser
it will default to localStorage
If your app is Native, it will default to AsyncStorage