import { useState, useEffect, SetStateAction } from 'react';


export default function useToken() {
  const [token, setToken] = useState('');
  useEffect(() => setToken(localStorage.getItem("token") || ""), []);
  const saveToken = (userToken: { token: SetStateAction<string>; }) => {
    localStorage.setItem('token', JSON.stringify(userToken));
    setToken(userToken?.token);
  };

  return {
    setToken: saveToken,
    token
  }
}