README
React hooks storage state
Library with web storage for state management with interface like React-hooks.
Install
$ npm install react-hooks-storage-state
Functions
export function useLocalStorageState<T>(key: string, defaultValue: T): [T, React.Dispatch<T>];
export function useSessionStorageState<T>(key: string, defaultValue: T): [T, React.Dispatch<T>];
Example
import React from 'react';
import logo from './logo.svg';
import { useSessionStorageState } from 'react-hooks-storage-state';
function App() {
const [msg, setMsg] = useSessionStorageState('msg', '');
return (
<div>
<input type="text" value={msg} onChange={e => setMsg(e.target.value)} />
</div>
);
}
export default App;