react-save-localstorage
Save and sync your data on render phase to localStorage safely
Try it live at StackBlitz
;; state = email: '' ; { return <div> /* Mode 1: read only */ <SaveLocalStorage lsKey="lang"> <div>Language: lang || '-'</div> </SaveLocalStorage> /* Mode 2: write only */ <SaveLocalStorage lsKey="emailBackup" value=thisstateemail /> /* Mode 3: dual */ <SaveLocalStorage value=thisstateemail lsKey="email"> <div> <input value=v onChange= this /> <div>Welcome v || 'Guest'</div> </div> </SaveLocalStorage> </div> ; }
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