S
S
Svyatoslav Khusamov2020-02-20 14:01:45
React
Svyatoslav Khusamov, 2020-02-20 14:01:45

What is the order of canceling effects (useEffect) in react components?

when the component is unmounted, for some reason, the effect cancellation is first called on the parent component, and then on the child ones... (we are talking about useEffect hooks)

Somehow it is not logical...

What could be the matter?

The problem is that I have map routes in my child components .. And when the routes are unmounted, they try to delete themselves in the map ... cancel effect on parent component is called before child components (child components learn about parent through context)

https://codesandbox.io/s/ocherednost-cancel-efekt...

See browser console

I expect:
Child cancel useEffect
Parent cancel useEffect

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Svyatoslav Khusamov, 2020-02-20
@khusamov

https://github.com/facebook/react/issues/16728

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question