import { useState, useEffect } from 'react';


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

  return {
    setToken: saveToken,
    token
  }
}