How to refresh page in React native?
Solution 1:
If you want to refresh the data of Flatlist, you can Use the extraData property on your FlatList component instead of changing route.
we can't use window.location.reload()
in React native.
Solution 2:
Since your source of data is from route.params.comments
. Flatlist not will not refresh data Since you have extraData as SelectedID.
Please have your data in state and pass the same state to extraData.
import React,{useState, useEffect} from 'react';
useEffect( () => {
const [comments, setComments] = useState(route?.params?.comments);
// update the comments after deleting using setComments() syntax;
},[])
//Both data & extraData is comments
const [selectedId, setSelectedId] = useState(null);
return (
<Container>
<CommentBox>
<FlatList
keyboardDismissMode={true}
showsVerticalScrollIndicator={false}
data={comments}
keyExtractor={(comment) => "" + comment.id}
renderItem={renderComment}
extraData={comments}
/>
</CommentBox>
</Container>
);
// You cannot use window.location.reload() in react native, but you can use in Web development