I am making an api call from useEffect
hook
function ChangePassword(props) {
const token = props.match.params.token;
const [state, setState] = useState({
password: "",
confirmPassword: "",
});
const [status, setStatus] = useState({
loaded: false,
auth: false,
});
useEffect(() => {
let { auth } = status;
axios
.get(
`http://localhost:2606/api/hostler/changepassword?token=${token}`
)
.then((res) => {
console.log("res", res);
auth = res.status === 202;
})
.then(() => setStatus({ auth, loaded: true }))
.catch((err) => console.log("err", err));
},[]);
return (
// code
);
}
But react gives warning
React Hook useEffect has missing dependencies: 'status' and 'token'. Either include them or remove the dependency array react-hooks/exhaustive-deps
also adding status
to dependency array will result in an infinite loop because setStatus
is called inside of useEffect