I have a function that sends register data to an endpoint
So I make a loading when user press sign-up button,
but this loading does not appear any more!
and i got a Warning
Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
I try tow different way to setState 'loading'
1) set state loading in the first line of my function then call my API.
this.setState({loading:true});
API.post(....);
2) make API calling int the callback function when setState loading as in the Below code snippet
but no one works :\
but sadly not works
signUp = data => {
this.setState({loading: true}, () => {
API.post('/register', data)
.then(async response => {
let {
data: {
data: {
response: {token},
},
},
} = response;
console.log(token);
this.props.dispatch(isLoginFunc(true));
await saveToken('id_token', token);
this.setState({loading: false}, () =>
this.props.navigation.navigate('TabHome'),
);
})
.catch(this.setState({loading: false}));
});
};
Calling signUp()
<Formik
validationSchema={formSchema}
initialValues={initialValues}
onSubmit={(values, actions) => {
this.signUp(values);
actions.resetForm();
}}>
....
</Formik>