Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6290

Passing callback as parameter to callback give me error Expected 1 arguments, but got 2

$
0
0

I'm tring to pass a callback to a set state but it gives me this typescript error => Expected 1 arguments, but got 2.ts(2554).i just wanted to pass a callback to setState to update the satate of the new object when function onVideoPlayed is called . can you help me ? thank you in advance

here is my code:

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>  );}

Viewing all articles
Browse latest Browse all 6290

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>