1.17.0 • Published 1 year ago
stook-localstorage v1.17.0
stook-localstorage
Installation
npm i stook-localstorage
Usage
string value
const App = () => {
const [value, setItem] = useLocalStorage('STORAGE_KEY', 'initialValue');
return (
<div>
<span>value</span>
<button onClick={() => setItem('newValue')}>update</button>
</div>
);
};
number value
const App = () => {
const [value, setItem] = useLocalStorage('STORAGE_KEY', 100);
return (
<div>
<span>{value}</span>
<button onClick={() => setItem(10)}>update</button>
</div>
);
};
boolen value
const App = () => {
const [value, setItem] = useLocalStorage('STORAGE_KEY', true);
return (
<div>
<span>{value}</span>
<button onClick={() => setItem(false)}>update</button>
</div>
);
};
object value
const App = () => {
const [user, setUser] = useLocalStorage('USER', { name: 'foo' });
return (
<div>
<pre>{JSON.stringify(user, null, 2)}</pre>
<button onClick={() => setUser({ name: 'bar' })}>set name</button>
</div>
);
};
getLocalStorage
getLocalStorage will return Object, not string
const data = getLocalStorage('USER');
License
1.15.0
1 year ago
1.14.0
1 year ago
1.17.0
1 year ago
1.16.0
1 year ago
1.13.0
2 years ago
1.12.0
2 years ago
1.11.0
2 years ago
1.9.0
3 years ago
1.8.0
3 years ago
1.7.0
3 years ago
1.10.0
3 years ago
1.6.1
3 years ago
1.5.1
3 years ago
1.5.0
3 years ago
1.4.0
3 years ago
1.3.0
3 years ago
1.2.2
3 years ago
1.2.0
3 years ago
1.2.1
3 years ago
1.1.1
3 years ago
1.1.0
3 years ago
0.0.2
4 years ago
0.0.1
4 years ago