In the example below, my groupData returns the correct set of data, but when I set the group, even after the .then(), the log for groups returns undefined. Am I using useEffect improperly? Additionally, when I set the second argument of the useEffect() to group, the log for groups does show the correct value, but obviously repeats the useEffect() over and over.
export const InvitePage = (props: any) => {
    const [group, setGroup] = useState<Group | undefined>();
    const [loading, setLoading] = useState(true);
    const getInviteKeyFromURL = () => {
        return props.location.search.split('=')[1];
    };
    const [inviteKey, setInviteKey] = useState(getInviteKeyFromURL());
    useEffect(() => {
        Groups.getGroupPreview(
            {},
            {
                groupInviteKey: inviteKey,
            },
        )
            .then((groupData) => {
                console.log('the result', groupData);
                setGroup(groupData);
            })
            .then(() => {
                console.log('group set', group);
                setLoading(false);
            });
    }, []);
}