1.1.8 • Published 3 days ago
react-mkx-storage v1.1.8
React Custom Hooks for Browser Storage Management
This package provides three custom React hooks for managing state in local storage, session storage and cookie storage: useLocalStorage
, useSessionStorage
and useCookieStorage
.
Installation
You can install the package using npm:
npm install react-mkx-storage
Or using yarn:
yarn add react-mkx-storage
useLocalStorage
A custom React hook to manage state in local storage.
Parameters
key
(string): The key under which to store the value in local storage.initialValue
(string | number | object | array): The initial value to use if no value is found in local storage.
Usage
import { useLocalStorage } from 'react-mkx-storage';
const MyComponent = () => {
const [value, setValue] = useLocalStorage('key', 'initialValue');
// Use value and setValue as needed
return (
// Your component JSX
);
};
useSessionStorage
A custom React hook to manage state in session storage.
Parameters
key
(string): The key under which to store the value in session storage.initialValue
(string | number | object | array): The initial value to use if no value is found in session storage.
Usage
import { useSessionStorage } from 'react-mkx-storage';
const MyComponent = () => {
const [value, setValue] = useSessionStorage('key', 'initialValue');
// Use value and setValue as needed
return (
// Your component JSX
);
};
useCookieStorage
A custom React hook to manage state in Cookie storage.
Parameters
key
(string): The key under which to store the value in Cookie storage.initialValue
(string | number | object | array): The initial value to use if no value is found in Cookie storage.
Usage
import { useCookieStorage } from 'react-mkx-storage';
const MyComponent = () => {
const [value, setValue] = useCookieStorage('key', 'initialValue');
// Use value and setValue as needed
return (
// Your component JSX
);
};
Browser Support
Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
License
This project is licensed under the ISC License - see the LICENSE file for details.
Author
1.1.8
3 days ago
1.1.7
8 days ago
1.1.6
20 days ago
1.1.5
27 days ago
1.1.4
27 days ago
1.1.3
27 days ago
1.1.1
2 months ago
1.1.2
2 months ago
1.1.0
2 months ago
1.0.9
2 months ago
1.0.8
2 months ago
1.0.7
2 months ago
1.0.6
2 months ago
1.0.5
2 months ago
1.0.4
2 months ago
1.0.3
2 months ago
1.0.2
2 months ago
1.0.1
2 months ago
1.0.0
2 months ago