type
status
date
slug
summary
tags
category
icon
password
Rendered more hooks than during the previous render
出现在需要兼容 Android 和 IOS 的时候,有一个组件的某个属性只希望在安卓上面有,而不希望在 IOS 上面有,就写成了这样:
问题:这里使用了条件性的 props 展开,在安卓和 iOS 平台上 RecyclerView 接收到的 props 不同,这可能导致:
- 组件内部状态不一致:RecyclerView 在安卓端有额外的 onRefresh 和 refreshing props
- 内部 hooks 调用差异:不同的 props 可能触发组件内部不同的 hooks 逻辑
仅在安卓上传递了 onRefresh 和 refreshing 这些 props,可能触发了内部的 useEffect、useState 等 hooks
修改:统一双端 props:
使用 useMemo 的时候,有一个变量在外部被计算但被用作依赖:
问题:
useMemo
的依赖数组[bottom]
引用了外部变量
- React 无法正确追踪这个依赖的变化
- 可能导致
useMemo
在某些渲染中被跳过或额外调用
修改:将计算逻辑移动到 useMemo 内部:
- Author:orangec
- URL:orange’s blog | welcome to my blog (clovy.top)/article/240c107a-b41d-8054-9a47-f1316dcb100d
- Copyright:All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!