I'm creating my own Image component and want to reuse React's image component ImageSourcePropType for my source/previewSource props.
Here's the component.
import React from 'react';
import { Image, ImageBackground } from 'react-native';
type ImageSourceProp = React.ComponentProps<typeof Image>.ImageSourcePropType; // HOW?
interface CachedImageProps {
source: ImageSourceProp;
previewSource: ImageSourceProp;
}
const CachedImage: React.FC<CachedImageProps> = ({ source, previewSource, ...remainingProps }) => {
// console.log('TRIGGERED CachedImage')
return (
<ImageBackground source={previewSource|| source} fadeDuration={0} {...remainingProps}>
<Image source={cachedSource} fadeDuration={0} {...remainingProps} />
</ImageBackground>
);
};
export default CachedImage;
How do I get the ImageSourcePropType?
'react-native'? The type is exported from the module, so you can add it to your list of imports easily:import { Image, ImageBackground, ImageSourcePropType } from 'react-native';