I have this React Native component:
type Props = { image: string, onPress: Function, text: string, title: String };
type States = { loadError: boolean };
export default class ProductRow extends Component<Props, States> {
state = {
loadError: false
};
changeToDefaultImg() {
this.setState({ loadError: true });
}
render() {
let img = this.state.loadError ? (
<SImage source={PLACEHOLDER} style={styles.placeholderImg} />
) : (
<Image
source={{ uri: this.props.image }}
indicator={ProgressCircleSnail}
indicatorProps={{ color: mainDark }}
onError={() => this.changeToDefaultImg()}
resizeMode="contain"
style={styles.image}
threshold={0}
/>
);
return (
// JSX
);
}
}
You can see that I haven't written:
constructor(props) {
super(props)
this.changeToDefaultImg = this.changeToDefaultImg.bind(this);
}
But I can use this function without any errors.
Please, explain to me, why it works.