Line 22:6: React Hook useEffect has a missing dependency: 'auth.token'. Either include it or remove the dependency array
Error
webpackHotDevClient.js:115 ./src/components/Layout/Routes/private.js
Line 22:6: React Hook useEffect has a missing dependency: 'auth.token'. Either include it or remove the dependency array
Line 22:7: React Hook useEffect has a complex expression in the dependency array. Extract it to a separate variable so it can be statically checked react-hooks/exhaustive-deps
Private.js
import { useState, useEffect } from "react";
import { useAuth } from "../../../context/auth";
import React from "react";
import { Outlet } from "react-router-dom";
import axios from "axios";
import Spinner from "../../spinner";
export default function PrivateRoute() {
const [ok, setOk] = useState(false);
const [auth] = useAuth();
useEffect(() => {
const authCheck = async () => {
const res = await axios.get("/api/v1/auth/user-auth");
if (res.data.ok) {
setOk(true);
} else {
setOk(false);
}
};
if (auth?.token) authCheck();
}, [auth?.token]);
return ok ? <Outlet /> : <Spinner />;
}
please suggest a change in the code to solve this issue
Via Active questions tagged javascript - Stack Overflow https://ift.tt/QmTaLjb
Comments
Post a Comment