I created a basic npm package component that allow me to put custom loading images at my Image component, but when I tried to use at my example app the component return undefined and this message appeared:
Could not find a declaration file for module 'react-native-default-image'.
After some researchs I find out that it's because the module doesn't provide any typings for TypeScript, but I'm not using TypeScript at all, my component is a .js file. There's some way to pass trought this?
My component file:
import React, { Component } from 'react';
import { Image } from 'react-native';
export default class DefaultImage extends React.Component {
state = { showDefault: true, error: false };
render() {
var image = this.state.showDefault ? this.props.defaultSource : ( this.state.error ? this.props.defaultSource : this.props.source );
return (
<Image style={this.props.style}
source={{uri: image}}
onLoadEnd={() => this.setState({showDefault: false})}
onError={() => this.setState({error: true})}
resizeMode={this.props.resizeMode}/>
);
}
}
My index file:
import { DefaultImage } from "./DefaultImage";
export { DefaultImage };
My package.json file:
{
"name": "react-native-default-image",
"version": "1.0.3",
"type": "module",
"description": "Image component that allow to set up a default image to be shown when the custom image is loading and when the custom image can't be loaded",
"main": "index.js",
"directories": {
"example": "example"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"react-native",
"image",
"default"
],
"author": "anti-duhring <mateusvnlima@gmail.com> (http://example.com)",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.17.10",
"@babel/preset-react": "^7.17.12",
"metro-react-native-babel-preset": "^0.71.0"
}
}
All my files: