reactjs - 平面列表渲染项的 React-Native 无效挂钩调用
问题描述
所以我有一个 react-native 平面列表,我在每个列表中都使用了钩子FlatList
renderItem
,就像这样,
export const RenderEntityList = (props) => {
const { entityList } = props;
const getEntityName = useCallBack((entity) => {
//...get Entity name from list
}, [entityList]);
return <FlatList
data={entityList}
renderItem={RenderEntity({ getEntityName })}
/>
};
const RenderEntity = (props) => {
const { getEntityName } = props;
return (props) => {
const { item: entity } = props;
// This is where i get the error Invalid hook call;
const [entityName, setEntityName] = useState('');
useEffect(() => {
setEntityName(getEntityName(entity))
}, [entity])
return <ListItem
title={entityName}
/>
};
我不确定我到底做错了什么。对此的任何帮助将不胜感激。
感谢和问候。阿莫尔
解决方案
您正在使用RenderEntity
asfunction
而不是 a functional component
:
改变这个
renderItem={RenderEntity({ getEntityName })}
和 :
renderItem={({item, index, separators}) => <RenderEntity item={item} getEntityName={getEntityName}/> }
推荐阅读
- mysql - 用于 MySQL 恢复的 Azure 数据库
- kubernetes - Istio Sidecar 注入失败
- html - 当我将鼠标悬停在下拉菜单上时,它不会保留
- typescript - 返回类型中数组中的keyof是什么意思?
- python - 从 Kubernetes 集群外部访问 Minio
- swiftui - 移动视图动画在模拟器上看起来超级迟钝,但在设备上很好
- vue.js - Vue 动态导入正在导入,即使从未使用过
- java - 重用流操作链
- typescript - “FirebaseFirestoreService”类错误地实现了“Firestore”类[错误 TS2720:]
- android - Recycler Adapter 中的协程