Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
How to fix missing dependency in React applications using useEffect?

Getting this error in my console. Not sure how to handle them

I am passing in guildId, so im not sure why its logging this error

src/utils/hooks/useFetchGuildBans.tsx

Line 22:6: React Hook useEffect has a missing dependency: 'guildId'. Either include it or remove the dependency array react-hooks/exhaustive-deps

Here is my useFetchGuildBans.tsx

import { useEffect, useState } from 'react';
import { getGuildBans } from '../api';
import { GuildBanType } from '../types';

export function useFetchGuildBans(guildId: string) {
  const [bans, setBans] = useState<GuildBanType[]>([]);
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState();
  const [updating, setUpdating] = useState(false);

  useEffect(() => {
    setLoading(true);
    getGuildBans(guildId)
      .then(({ data }) => {
        setBans(data);
      })
      .catch((err) => {
        console.log(err);
        setError(err);
      })
      .finally(() => setLoading(false));
  }, [updating]);

  return { bans, loading, error, updating, setUpdating };
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  useEffect(() => {
    setLoading(true);
    getGuildBans(guildId)
      .then(({ data }) => {
        setBans(data);
      })
      .catch((err) => {
        console.log(err);
        setError(err);
      })
      .finally(() => setLoading(false));
  }, [updating, guildId]);

The second parameter of useEffect is called the dependencies array. The error message is saying that guildId is missing from this array.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!