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

272
Views
Please report: Excessive number of pending callbacks: 501 when called inside of useEffect

I am using React JS, Redux, React- Redux , Redux-Thunk.

File: Acions.js: Here are my Redux Action functions:

export function setSuccess(data){
    return{
        type: "SET_SUCCESS",
        payload: data
    };
}


export function setMessage(data){
    return{
        type: "SET_POSTS",
        payload: data
    };
}


export const listMyBlogPosts = (userID, abortController) =>{

    return (dispatch) =>{
        axios.get(`http://locahost:5000/timeline/posts/${userID}`, {signal: abortController})
            .then((response) =>{
                dispatch(setSuccess(true));
                dispatch(setMessage(response.data.message));

            }).catch((error) =>{
                console.log("err: ", error);
                dispatch(setSuccess(false));
                dispatch(setMessage(`${error}`));
            });
    }

};

Here is where I am using the above function:

File: ABC.js:

function ABC({ someCheck }){
    const abortController = useRef(new AbortController()); 
    const dispatch = useDispatch();
    console.log(“ABC component”);

    useEffect(() =>{
       
        navigation.addListener("focus", () =>{

            dispatch(listMyBlogPosts(userID, abortController.current.signal));
            
            console.log("focus is being run!");

        });

        return () => abortController.current.abort();

    }, []);   
    
}

In the ABC component, I get the following error:

error message

If I remove the useEffect hook, I do not get the above error ?

How to fix this error ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your code is adding more and more event 'focus' listeners, which is leading to lots of request call. So you need to remove those event listener once component is unmounted.

useEffect(() => {
  const onFocus = () => {
    dispatch(listMyBlogPosts(userID, abortController.current.signal))
    console.log('focus is being run!')
  }
  navigation.addListener('focus', onFocus)

  return () => {
    navigation.removeListener('focus', onFocus)
    abortController.current.abort()
  }
}, [])

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!