npm.io
1.0.2 • Published 6 years ago

preact-localstorage

Licence
MIT
Version
1.0.2
Deps
0
Size
5 kB
Vulns
0
Weekly
0
Stars
1

reactLocalStorage

Easy use localstorage in Preact. It also supports SSR (Prerender).

Installation

npm install preact-localstorage

or

yarn add preact-localstorage

Examples

import preactLocalStorage from 'preact-localstorage';

preactLocalStorage.set('var', true);
preactLocalStorage.get('var', true);
preactLocalStorage.setObject('var', {'test': 'test'});
preactLocalStorage.getObject('var');
preactLocalStorage.remove('var');
preactLocalStorage.clear();

API Guide

Default VALUE is required while getting values (because SSR doesn't have real localStorage)

  • preactLocalStorage.set(key, value)
  • preactLocalStorage.get(key, deafultValue, silent=true)
  • preactLocalStorage.setObject(key, object)
  • preactLocalStorage.getObject(key, defaultValue, silent=true)
  • preactLocalStorage.remove(key)
  • preactLocalStorage.clear()

silent:

  • true: Will not throw exception instead will return defaultValue
  • false: Will throw exception

License

MIT

Keywords