I recently encountered a warning
stating that I cannot update during render. The recommendation was to update in ComponentWillMount
. However, since I need to change the state after checking if the image is in an Error (not Loaded)
state, I must make the state change within the render function.
_onError = (index) => {
let data = this.state.data;
if (data[index].imageError === false) {
data[index].imageError = true;
this.setState({ data: data });
}
}
render() {
this.state.data.map((n, index) => {
<Image
source={
n.imageError
? rightImg
: {
uri: `${notRightImg}`
}
}
style={{ width: 50, height: 50 }}
onError={this._onError(index)}
/>
})
}