This package provides custom React hooks for managing state in local storage, session storage and cookie storage: useLocalStorage, useSessionStorage and useCookieStorage.
npm install react-mkx-storage!NPM !npm
!npm !NPM !NPM Unpacked Size
This package provides three custom React hooks for managing state in local storage, session storage and cookie storage: useLocalStorage, useSessionStorage and useCookieStorage.
You can install the package using npm:
``bash`
npm install react-mkx-storage
Or using yarn:
`bash`
yarn add react-mkx-storage
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
`jsx
import { useLocalStorage } from 'react-mkx-storage';
const MyComponent = () => {
const [value, setValue] = useLocalStorage('key', 'initialValue');
// Use value and setValue as needed
return (
// Your component JSX
);
};
`
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
`jsx
import { useSessionStorage } from 'react-mkx-storage';
const MyComponent = () => {
const [value, setValue] = useSessionStorage('key', 'initialValue');
// Use value and setValue as needed
return (
// Your component JSX
);
};
`
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
`jsx
import { useCookieStorage } from 'react-mkx-storage';
const MyComponent = () => {
const [value, setValue] = useCookieStorage('key', 'initialValue');
// Use value and setValue as needed
return (
// Your component JSX
);
};
``
| !Chrome | !Firefox | !Safari | !Opera | !Edge | !IE |
| ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
| Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ | 11 ✔ |
This project is licensed under the ISC License - see the LICENSE file for details.


