android - React Native App 中的 RecyclerListView 警告
问题描述
我在运行 React Native App 时收到此警告。谁能帮帮我?我在代码中找不到任何问题。但我仍然收到这个警告。该程序也运行良好。但是警告每次都会出现,我现在很想解决这个问题。
有谁知道为什么会出现这个警告?
You have mounted RecyclerListView with an empty data provider (Size in 0). Please mount only if there is atleast one item to ensure optimal performance and to avoid unexpected behavior
at node_modules\react-native\Libraries\LogBox\LogBox.js:117:10 in registerWarning
at node_modules\react-native\Libraries\LogBox\LogBox.js:63:8 in warnImpl
at node_modules\react-native\Libraries\LogBox\LogBox.js:36:4 in console.warn
at node_modules\expo\build\environment\react-native-logs.fx.js:18:4 in warn
at node_modules\recyclerlistview\dist\reactnative\core\RecyclerListView.js:210:12 in prototype.componentDidUpdate
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:15732:12 in commitLifeCycles
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18744:22 in commitLayoutEffects
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:265:4 in invokeGuardedCallbackImpl
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:476:2 in invokeGuardedCallback
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18483:29 in commitRootImpl
at [native code]:null in commitRootImpl
at node_modules\scheduler\cjs\scheduler.development.js:653:23 in unstable_runWithPriority
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:18317:17 in commitRoot
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17697:12 in performSyncWorkOnRoot
at [native code]:null in performSyncWorkOnRoot
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5321:31 in runWithPriority$argument_1
at node_modules\scheduler\cjs\scheduler.development.js:653:23 in unstable_runWithPriority
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5316:21 in flushSyncCallbackQueueImpl
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:5304:28 in flushSyncCallbackQueue
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:17125:30 in scheduleUpdateOnFiber
at node_modules\react-native\Libraries\Renderer\implementations\ReactNativeRenderer-dev.js:7267:16 in classComponentUpdater.enqueueSetState
at node_modules\react\cjs\react.development.js:471:2 in Component.prototype.setState
at node_modules\recyclerlistview\dist\reactnative\core\RecyclerListView.js:423:13 in prototype._queueStateRefresh
at node_modules\recyclerlistview\dist\reactnative\core\RecyclerListView.js:70:14 in RecyclerListView
at node_modules\lodash.debounce\index.js:159:21 in invokeFunc
at node_modules\lodash.debounce\index.js:206:20 in trailingEdge
at node_modules\lodash.debounce\index.js:194:20 in timerExpired
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:383:16 in callTimers
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 in __callFunction
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 in callFunctionReturnFlushedQueue
at [native code]:null in callFunctionReturnFlushedQueue
解决方案
RecyclerListView 组件在获取或加载数据之前挂载。所以用条件渲染包装它,以便仅在有数据时运行。
例子:
return (
{dataProvider && dataProvider.getSize() > 0 &&
<RecyclerListView
..../>
}
)
推荐阅读
- javascript - 未考虑 NodeJS 的 json 更改
- javascript - 使用 AWS CDK 合成 lambda 函数时,为什么会出现“this.combinedGrant 不是函数”?
- powershell - 如何从 Select-Object 中获取部分结果
- pine-script - 如何绘制连续合约的期货溢价/倒价?
- javascript - 是否可以在js中更改事件冒泡顺序
- python - 根据值填充数据框列
- c++ - GLSL 简单示例在 OSX 上显示空白屏幕
- python - 为什么我的索引超出范围?IndexError:列表索引超出范围
- javascript - 意外的令牌,`else`
- python - 选择熊猫中没有空列表的行