Why are effects named as "passive effects" in React source code?

1.9k views Asked by At

As a non native english speaker, i am confused by the term "passive effects", as in schedulePassiveEffects, cancelPassiveEffects in React source code. What exactly does 'passive' mean here?

1

There are 1 answers

0
windmaomao On BEST ANSWER

The reason why it's not just called effect is that there're other Effects in React. There're mutation effects and layout effects along with passive ones.

The passive one is the common one which listens to a state change (through a dependency array) and then can invoke a callback that changes other states.

What's unique about a passive effect is, it waits for all UI (render and commit) to settle down before invoking them in another time slice. So the callback happens in a Javascript time slice similar to an event handler (ex. onClick).

I believe this is where it gets its name, the "passive". Because instead of actively handling an event, it's passively listen to a state change and invoke a callback. I wrote a blog about this, https://javascript.plainenglish.io/is-a-react-passive-effect-an-artificial-event-2535977b9a91