@yangchanghao/use-effect-storage
TypeScript icon, indicating that this package has built-in type declarations

0.0.2-alpha.1 • Public • Published

@yangchanghao/use-effect-storage使用说明

实时监听本地缓存(localStorage|sessionStorage)里值的变化,并触发你希望执行的回调函数,在vue/react的路由或者组件的生命周期销毁函数去销毁该hooks实例

Vue3.x下使用

<template>
  <div>............</div>
</template>

<script lang='ts' setup>
import useEffectStorage from '@yangchanghao/use-effect-storage/vue';

useEffectStorage((e)=>{
  // key: 改变的storage的key
  // value: 改变的storage的key对应的value
  // storageType: localStorage | sessionStorage
  const {key,value,storageType} = e;
},['name1','name2','name3'],'localStorage');

</script>

React(FunctionComponent)下使用

import React,{ FunctionComponent } from 'react';
import useEffectStorage from '@yangchanghao/use-effect-storage/react';

const Index: FunctionComponent<any> = (props)=>{
    
    useEffectStorage((e)=>{
      // key: 改变的storage的key
      // value: 改变的storage的key对应的value
      // storageType: localStorage | sessionStorage
      const {key,value,storageType} = e;
    },['name1','name2','name3'],'sessionStorage')

    return (
        <div>...............</div>
    )
}

export default Index;

Readme

Keywords

none

Package Sidebar

Install

npm i @yangchanghao/use-effect-storage

Weekly Downloads

0

Version

0.0.2-alpha.1

License

ISC

Unpacked Size

16.4 kB

Total Files

7

Last publish

Collaborators

  • yangchanghao