Problem
I am writing an application in react native but unable to fix this particular warning. I understand this is caused by making a request for data, but the component unmounts before request is completed. Also, i have applied some solutions found here but can't get it to work. This is my code, and i have applied the solution below too.
class PeopleScreen extends React.Component {
constructor(props) {
super(props);
this.state = {
listData : [ ]
};
}
componentDidMount() {
// Get list of people.
AsyncStorage.getItem("people",
function(inError, inPeople) {
if (inPeople === null) {
inPeople = [ ];
} else {
inPeople = JSON.parse(inPeople);
}
this.setState({ listData : inPeople });
}.bind(this)
);
};
render() { return (
)
This is the solution i have applied:
class PeopleScreen extends React.Component {
_isMounted = false;
constructor(props) {
super(props);
this.state = {
listData : [ ]
};
}
componentDidMount() {
this._isMounted = true;
// Get list of people.
AsyncStorage.getItem("people",
function(inError, inPeople) {
if (inPeople === null) {
inPeople = [ ];
} else {
inPeople = JSON.parse(inPeople);
}
this.setState({ listData : inPeople });
}.bind(this)
);
};
componentWillUnmount() {
this._isMounted = false;
}
render() { return (
)