Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

父子组件均使用usePageEvent('onShow'), 在子组件onshow中改变组件状态,返回该页面时,父组件钩子不会执行,子组件钩子重复执行 #1564

Closed
chqfly opened this issue May 7, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@chqfly
Copy link

chqfly commented May 7, 2021

bug 描述
父子组件均使用usePageEvent('onShow'), 在子组件onshow中改变组件状态,离开当前页面再返回该页面时,父组件onShow钩子不会执行,子组件onShow钩子会重复执行。
如果去掉 setCount(count + 1),则正常执行。

复现步骤
离开页面再返回页面

期望结果
父组件钩子执行,子组件钩子均执行,且执行一次

复现代码

export default function DemoLifecycle() {
  usePageEvent('onShow', () => {
    console.log('parent======')
  })
  return (
    <View>
      <Button onTap={() => navigateTo({ path: '/pages-women/pharmacy/medication-clock/index' })}>
        jump
      </Button>
      <DemoChildren />
    </View>
  )
}
export default function DemoChildren() {
  const [count, setCount] = useState<number>(0)
  usePageEvent('onShow', () => {
    console.log('child======')
    setCount(count + 1)
  })
  return <View>{count}</View>
}

版本信息:

  • remax 版本: [2.7.8]
  • 手机型号 [模拟器、真机]
  • 小程序端 [微信小程序]
  • 小程序版本[2.16.1]
  • 开发环境 [mac OS]

其他信息

@chqfly chqfly added the bug Something isn't working label May 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant