我试图传递回调到一个设置状态,但它给我这个typescript错误=〉预期1参数,但得到2.ts(2554).我只是想传递一个回调到setState,以更新新对象的状态时,函数onVideoPlayed被调用.你能帮助我吗?谢谢你提前
下面是我代码:
const [videos, setVideos] = useState<Video[]>(videosList);
const [currentLanguage, setCurrentLanguage] = useState(i18n.language);
const navigation = useNavigation();
const renderItem = ({item, index}: {item: Video; index: number}) => {
return (
<Pressable onPress={() => onVideoPlayed(item, index)}>
<Card video={item} currentLanguage={currentLanguage} />;
</Pressable>
);
};
function onVideoPlayed(video: Video, index: number) {
if (video.viewedTimes && video.viewedTimes > 0) return;
let newVideos = videos;
newVideos[index].viewedTimes++;
setVideos(newVideos, () => {}); ===> "here it gives me the error"
}
return (
<View style={{flex: 1}}>
<FlatList
data={videos}
keyExtractor={item => item.title}
renderItem={({item, index}) => renderItem(item, index)}
numColumns={4}
contentContainerStyle={appStyles.cardListStyle}
/>
</View>
);
}
2条答案
按热度按时间7cwmlq891#
bvjveswy2#
试试看