Skip to content

MdWahiduzzamanEmon/-emon-browser_storage_hook_react

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Browser Storage Hook React

This is a React hook that allows you to use the browser storage API in a simple way.

Installation

Use the package manager npm/yarn to install the package.((please read the documentation first))

npm i browser_storage_hook_react
yarn add browser_storage_hook_react
Screen.Recording.2022-11-21.at.3.52.58.PM.mov

Importing

import { useLocalStorage, useSessionStorage, useCookie, setCookie, getCookie } from 'browser_storage_hook_react';

How to use it

Local Storage

const [value, setValue] = useLocalStorage('key', 'defaultValue');

Session Storage

const [value, setValue] = useSessionStorage('key', 'defaultValue');

Cookie

const [value, setValue] = useCookie('key', 'defaultValue', expiry);

Manually set and get cookie

const value = getCookie('key');
setCookie('key', 'value', expiry);

Local Storage and Session Storage

Here value is the value stored in the browser storage ,
and setValue is the function to set the value in the browser storage.

Cookie

Here value is the value stored in the cookie ,
and setCookie is the function to set the value in the cookie.

Name Type Description
key string The key of the value to be stored
value string The value to be stored
defaultValue string The default value to be stored
expiry number The expiry time of the cookie

License

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

Author

  • md-wahiduzzaman-emon [Md Wahiduzzaman Emon]

Contributing

  • Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
  • Please make sure to update tests as appropriate.

About

This is a React hook that allows you to use the browser storage API in a simple way. (npm i browser_storage_hook_react)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published