我正在将函数传递给
MapComponent
以下为:
type Props = {
results: SearchResult[];
...
onDirectionsPress: (
latitude: number,
longitude: number,
sitename: string,
) => void;
};
const MapTab = ({
results,
fuelType,
searchDistance,
addressName,
onDirectionsPress,
}: Props) => (
<View style={styles.container}>
...
<MapComponent results={results} {...onDirectionsPress} />
</View>
);
在我的
地图组件
,显示为
undefined
,在TypeScript中出现上述错误时,我如何将函数传递到
地图组件
?
type Props = {
results: SearchResult[];
onDirectionsPress: (
latitude: number,
longitude: number,
sitename: string,
) => void;
};
const MapComponent = ({ results, onDirectionsPress }: Props) => {
console.log('here', results, onDirectionsPress); <<< undefined
return (
<View style={styles.container}>
<MapView
ref={mapRef}
minZoomLevel={2} // default => 0
maxZoomLevel={15}
provider={PROVIDER_GOOGLE}
style={styles.map}>
{Markers}
</MapView>
{showCard && <SearchResultCard {...resultProps} />}
</View>
);
};
export default MapComponent;