import { useActions } from "../overmind";
import { useEffect, useState } from "react";
export const useBadges = (userId) => {
    const [badges, setBadges] = useState();
    const [isBadgesLoading, setIsBadgesLoading] = useState(false);
    const [badgesError, setBadgesError] = useState();
    const actions = useActions();
    useEffect(() => {
        const badgesReq = async () => {
            const badges = (await actions.api.user.getBadges({ id: userId || "" })).value;
            setBadges(badges);
        };
        try {
            setIsBadgesLoading(true);
            badgesReq();
            setIsBadgesLoading(false);
            setBadgesError(undefined);
        }
        catch (e) {
            setIsBadgesLoading(false);
            setBadgesError(e.message);
        }
    }, [userId]);
    return { badges, isBadgesLoading, badgesError };
};
//# sourceMappingURL=useBadges.js.map