I'm trying to get my incident object from route.params but I don't know how to do it to make typescript recognize this prop.
Here is the function that navigate to my Detail page passing incident to params:
const navigateToDetail = (incident: IncidentProps): void => {
navigation.navigate('Detail', { incident });
};
And Here is part of Detail page code where I try to get this object from route.params:
type IncidentRouteParams = {
incident: IncidentProps;
}
const Detail: React.FC = () => {
const navigation = useNavigation();
const route = useRoute();
const incident = route.params.incident;
I think I need to pass this IncidentRouteParams type somehow to const route = useRoute()
Thanks in advance.
Here is the image with the error
EDIT:
I did like this, and it worked, but I don't know if it is the right way:
const route = useRoute<RouteProp<Record<string, IncidentRouteParams>, string>>();
const incident = route.params.incident;