Maximum update depth exceeded error using User Menu component #3610
Unanswered
pphmtrungkin
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there. I'm doing my personal project using Supabase for the database. I'm fetching the array from the database and use it for the player menu component. I appreciate the help if anyone can spot the error.
const Game = () => { const [players, setPlayers] = useState([]); const {user} = useContext(UserContext) const fetchPlayers = async () => { if (user) { const { data, error } = await supabase .from("players") .select("*") .eq("user_id", user.id); if (error) { console.error("Error fetching players: ", error.message); return; } setPlayers(data); } }; return ( <PlayerSelect players={players} /> ) }
`const PlayerSelect = ({ players }) => {
const [selected, setSelected] = useState(players[0] || null);
return (
{selected && selected.avatar_url ? (
{selected.name}
) : (
)}
);
};`
Beta Was this translation helpful? Give feedback.
All reactions