1.17.0 • Published 2 years ago

stook-localstorage v1.17.0

Weekly downloads
3
License
MIT
Repository
github
Last release
2 years ago

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

MIT License

1.15.0

2 years ago

1.14.0

2 years ago

1.17.0

2 years ago

1.16.0

2 years ago

1.13.0

3 years ago

1.12.0

3 years ago

1.11.0

3 years ago

1.9.0

4 years ago

1.8.0

4 years ago

1.7.0

4 years ago

1.10.0

4 years ago

1.6.1

4 years ago

1.5.1

4 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

0.0.2

6 years ago

0.0.1

6 years ago