Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/null-none/react-localstorage

Easy methods for use localstorage in Reactjs.
https://github.com/null-none/react-localstorage

javascript js localstorage nodejs react reactjs

Last synced: 2 months ago
JSON representation

Easy methods for use localstorage in Reactjs.

Awesome Lists containing this project

README

        

# reactLocalStorage
Easy use localstorage in Reactjs

https://www.npmjs.com/package/reactjs-localstorage

## Installation

```bash
npm install reactjs-localstorage
```
or
```bash
yarn add reactjs-localstorage
```

## Examples

```javascript
import {reactLocalStorage} from 'reactjs-localstorage';

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

## Test

```bash
npm run test
```

## API Guide
- `reactLocalStorage.set(key, value)`
- `reactLocalStorage.get(key, deafultValue=undefined, silent=true)`
- `reactLocalStorage.setObject(key, object)`
- `reactLocalStorage.getObject(key, defaultValue={}, silent=true)`
- `reactLocalStorage.remove(key)`
- `reactLocalStorage.clear()`

**silent**:
- `true`: Will not throw exception instead will return defaultValue
- `false`: Will throw exception

## License
MIT

## Donation Button

[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YYZQ6ZRZ3EW5C)