I have a state with a token that i get from my api :
const initialState = {
isAuth: false,
token: "",
};
And I want to reuse the token in an Axios instance :
const api = axios.create({
baseURL: `${baseUrl}`,
headers: {
Authorization: `Bearer ${token}`,
},
});
export default api;
The problem is that I can not read the token via useSelector as :
const token = useSelector((state) => state.auth.token);
I get the error message :
invalid hook call. hooks can only be called inside of the body of a function component
Any suggestion ? Thanks in advance