@rehmat-falcon/use-local-storage

1.0.0 • Public • Published

@rehmat-falcon/use-local-storage

NPM JavaScript Style Guide

This hook allows you to access the localstorage for a certain key.

Support for objects have been added. If your initial value is an object, it will deserialize when retrieving and serialize when saving the object.

Install

npm install --save @rehmat-falcon/use-local-storage

Usage

import React, { Component } from 'react'

import { useLocalStorage } from '@rehmat-falcon/use-local-storage';

const Example = () => {
  const localStorageManager = useLocalStorage("key", {});
  // check if the key exists using localStorageManager.state.exists
  return (
    <div>{localStorageManager.state.value}</div>
  )
}

Hook Definition

useLocalStorage(key, initialValue = "", override = false);

key : The key in which to save the value

initialValue : The value to use if no value is present

override : If set to true, the initialValue will be saved into the localStorage by overriding the current value.

License

MIT © RehmatFalcon


This hook is created using create-react-hook.

Readme

Keywords

none

Package Sidebar

Install

npm i @rehmat-falcon/use-local-storage

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

1.41 MB

Total Files

24

Last publish

Collaborators

  • rehmat-falcon