I need help accessing my incident object from route.params in TypeScript.
Below is the function I use to navigate to my Detail page and pass the incident object:
const navigateToDetail = (incident: IncidentProps): void => {
navigation.navigate('Detail', { incident });
};
Here is a snippet of code from my Detail page where I try to retrieve 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 believe I need to somehow specify the IncidentRouteParams type when using const route = useRoute()
Thank you for your assistance!
Displayed below is the image showing the error message:
EDIT:
I managed to resolve it by doing the following, although I am unsure if it's the correct approach:
const route = useRoute<RouteProp<Record<string, IncidentRouteParams>, string>>();
const incident = route.params.incident;