Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antonybudianto/react-save-localstorage
🗄 React component to save data to localStorage on render phase safely
https://github.com/antonybudianto/react-save-localstorage
local-storage localstorage react reactjs render-props
Last synced: 3 months ago
JSON representation
🗄 React component to save data to localStorage on render phase safely
- Host: GitHub
- URL: https://github.com/antonybudianto/react-save-localstorage
- Owner: antonybudianto
- License: mit
- Created: 2018-11-24T04:33:53.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-08T19:14:59.000Z (about 2 years ago)
- Last Synced: 2024-10-12T23:46:43.907Z (4 months ago)
- Topics: local-storage, localstorage, react, reactjs, render-props
- Language: JavaScript
- Homepage:
- Size: 1.79 MB
- Stars: 26
- Watchers: 2
- Forks: 1
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-save-localstorage
[![npm version](https://badge.fury.io/js/react-save-localstorage.svg)](https://badge.fury.io/js/react-save-localstorage)
[![Build Status](https://travis-ci.org/antonybudianto/react-save-localstorage.svg?branch=master)](https://travis-ci.org/antonybudianto/react-save-localstorage)
Save and sync your data on render phase to localStorage safely
> Try it [live at StackBlitz](https://stackblitz.com/edit/demo-react-save-localstorage)
```js
import React, { Component } from 'react';
import SaveLocalStorage from 'react-save-localstorage';class Home extends Component {
state = {
email: ''
};
render() {
return (
{/* Mode 1: read only */}
{lang =>Language: {lang || '-'}}
{/* Mode 2: write only */}
{/* Mode 3: dual */}
{v => (
this.setState({
email: e.target.value
})
}
/>
Welcome, {v || 'Guest'}
)}
);
}
}
```## Props
- **lsKey** (string, required)
- **value** (string)
- **sync** (bool)To sync after value updates, default is `true`
- **children** (func)
Function that accept loaded **value** from localStorage
- **onSave** (func)
Function that accept object containing:
- `init` (boolean that indicated it's the first mount)
- `value` (the value being saved)This is called for every value updates.
## License
MIT