0.0.5 • Published 1 year ago

@garthmcrae/use-storage v0.0.5

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

Use storage

A React hook similar to React.useState that stores state in storage. State can be accessed anywhere in the application without the need for wrapping your application and or components in a provider.

Install

npm install --save @garthmcrae/use-storage

Usage

import useStorage from "@garthmcrae/use-storage";

const config = {
  key: "STORAGE_NAME",
  value: { foo: "boo", bar: "far" },
};

function Component() {
  const [storage, setStorage] = useStorage(config);
  return (
    <div className="Component">
      <h2>Component</h2>
      <button
        onClick={function () {
          setStorage({ ...storage, foo: "baz" });
        }}
      >
        Set {storage.foo} to baz
      </button>
    </div>
  );
}

export default Component;

Dependencies

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.0

1 year ago