React native Warning: Can't perform a React state update on an unmounted component Hook code example
Example 1: react warning can't perform a react state update on an unmounted component
componentWillUnmount() {
this.setState = (state,callback)=>{
return;
};
}
Example 2: Can't perform a React state update on an unmounted component
useEffect(() => {
const source = axios.CancelToken.source()
const fetchUsers = async () => {
try {
await Axios.get('/users', {
cancelToken: source.token,
})
} catch (error) {
if (Axios.isCancel(error)) {
} else {
throw error
}
}
}
fetchData()
return () => {
source.cancel()
}
}, [])