// /swr/project.js
import useSWR, { mutate } from 'swr'
export async function fetchProject (id) {
mutate(`/api/project/${id}`, fetch(`/api/project/${id}`))
}
export default function useProject (id) {
// don't pass the fetcher so it won't fetch
return useSWR(`/api/project/${id}`)
}
// components/project.js
function Project ({ id }) {
const { data } = useProject(id)
return <>
{data}
<button onClick={() => fetchProject(id)}>fetch!</button>
</>
}
token and logout
So every time you refocus on a window, the token gets reloaded.
Logout: