You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-mkx-storage

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-mkx-storage

This package provides custom React hooks for managing state in local storage, session storage and cookie storage: useLocalStorage, useSessionStorage and useCookieStorage.

1.1.8
latest
npmnpm
Version published
Weekly downloads
30
400%
Maintainers
1
Weekly downloads
 
Created
Source

React Custom Hooks for Browser Storage Management

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.

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

ChromeFirefoxSafariOperaEdgeIE
Latest ✔Latest ✔Latest ✔Latest ✔Latest ✔11 ✔

License

This project is licensed under the ISC License - see the LICENSE file for details.

Author

Mani Kant Sharma

Email Instagram GitHub

Keywords

reactjs

FAQs

Package last updated on 30 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts