Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useLocalSorageState无法监听全局localStorage修改的事件 #2516

Closed
cwtuan opened this issue Apr 9, 2024 · 1 comment · Fixed by #2298
Closed

useLocalSorageState无法监听全局localStorage修改的事件 #2516

cwtuan opened this issue Apr 9, 2024 · 1 comment · Fixed by #2298

Comments

@cwtuan
Copy link

cwtuan commented Apr 9, 2024

在两个View,都使用同样的key。

  1. 第一个View修改的localStorage的值
  2. 第二个View感知不到,没有重新渲染

看了代码,发现ahooks的实现,没有监听了全局的StorageEvent。

目前暂时改用另一个包usehooks-ts,这个包监听全局localStorage修改的事件。

const View1 = ()=>{
   const [state, setState] = useLocalSorageState('mykey')
   return (<Button onClick={()=>{setState('AAA')}}><Button>)
}

const View2 = ()=>{
   const [state, setState] = useLocalSorageState('mykey')
   console.log(state)
}
@liuyib
Copy link
Collaborator

liuyib commented Apr 9, 2024

在处理了:#2298
耐心等待合并哈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants