I have a functional component called signup in which I am using react-intl-tel-input for mobile number field. There is only one async axios request which is happening on submitting the form. But still I am getting this warning
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 the componentWillUnmount method.
I want to remove this warning but so far I tried several solutions provided on Stackoverflow does not work. After debugging I found out the warning is generating from <IntlTelInput /> field from react-intl-tel-input.
Please help me out to remove this warning.
Code example:
import React, {useState} from "react";
import IntlTelInput from "react-intl-tel-input";
import axios from "axios";
function Signup() {
const [password, setPassword] = useState("");
const [email, setEmail] = useState("");
const [mobile, setMobile] = useState("");
const handleSubmit = async (e) => {
const signupData = { email, password, mobile};
const response = await axios.post(/url, signupData);
}
return (
<form onSubmit={handleSubmit}>
<input name="email" type="text" onChange={e => setEmail(e.target.value)} />
<input name="password" type="password" onChange={e => setPassword(e.target.value)} />
<IntlTelInput
containerClassName="intl-tel-input"
inputClassName="form-control w-100"
autoPlaceholder
separateDialCode
defaultCountry="za"
name="mobile"
numberType="MOBILE"
fieldId="mobile_number"
onPhoneNumberChange={(validate, value, countryData) =>
setMobile(value)
}
formatOnInit={false}
autoComplete="new-phone"
/>
<button type="submit">Signup</button>
);
export default Signup;