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

Taro Event on 的处理函数内 无法获取到最新state 获取到的永远是state的初始值 #9883

Open
scrapstation opened this issue Jul 24, 2021 · 2 comments
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@scrapstation
Copy link

相关平台

微信小程序

复现仓库

https://github.com/6ok/Taro.Event.State.Bug
小程序基础库: 2.18.1
使用框架: React

复现步骤

使用Taro.eventCenter处理事件,获取state时,state的值恒为初始值

期望结果

state为最新值

实际结果

state为初始值

环境信息

👽 Taro v3.3.1


  Taro CLI 3.3.1 environment info:
    System:
      OS: Windows 10
    Binaries:
      Node: 14.17.1 - C:\Program Files\nodejs\node.EXE
      Yarn: 1.22.10 - C:\Users\liuke\AppData\Roaming\npm\yarn.CMD
      npm: 6.14.13 - C:\Program Files\nodejs\npm.CMD
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Jul 24, 2021
@jessejyang
Copy link

demo 里 useReady 渲染时只执行了一次,Taro.eventCenter.on("showNumber", handleShowNumber) 闭包了呀~

@scrapstation
Copy link
Author

demo 里 useReady 渲染时只执行了一次,Taro.eventCenter.on("showNumber", handleShowNumber) 闭包了呀~
@jjjyy
请教下 我应该怎么写解决这个问题呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

2 participants