Dani Rueda
Dani Rueda

Reputation: 1

React prevent our code from setting state if the component has been unmounted

I have this on the useEffect, I receive that error:

Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.

useEffect(() => { top_10_articles(); ventas_mes_actual(); }, [])

Upvotes: 0

Views: 49

Answers (1)

CyberMessiah
CyberMessiah

Reputation: 1268

I will try to give you some clues but better provide the code for the two functions. I guess they are either asynchronous or depend on external source. You may need to add a cleanup function. Refer to this link.

useEffect(() => { 
    top_10_articles(); 
    ventas_mes_actual();  
    return function cleanup() {
       ..... undo the setters for example, depending on the above functions
    };
}, [])

Upvotes: 1

Related Questions