import { useEffect, useState } from 'preact/hooks'

export const useUser = () => {
    const [username, setUsername] = useState(null)

    useEffect(async () => {
        const res = await fetch(`/api/current-user`, {
            credentials: 'include',
        })
        const username = await res.json()
        setUsername(username)
    }, [])

    return { username }
}
