3 ms·
I'm having hard time understanding why `useEffectEvent` is so limited. > * Only call them from inside Effects. > * Never pass them to other components or Hook
by febusravenga 4y ago
I'm having hard time understanding why `useEffectEvent` is so limited.
> * Only call them from inside Effects.
> * Never pass them to other components or Hooks.
(https://react.dev/learn/separating-events-from-effects#limitations-of-effect-events https://react.dev/learn/separating-events-from-effects#limit...)
The original proposal was more about `events` this one is about effects.
According to these rules, i can't do
const x = useEffectEvent((event) => console.log("abc"))
return <MyCustmButton onClick={x}/>
Why isn't it allowed?
- Rapzid 4y agoTBH I can't even figure out what useEffectEvent does after reading the docs and looking at just about every Google hit for it. Please let me know if you figure it out.
- aidos 4y agoThe idea with them is to “break” reactivity. In the local space where you define them that’s totally fine because you’re obviously doing it in order to have useEffects that only run when their real dependencies change. If these are passed down you’re invisibly breaking the reactivity of the child components. It’ll be too easy to shoot yourself in the foot in a child component by assuming that that you can use one of these in your own useEffect.
- febusravenga 4y agoI really strive to find actual example of shooting myself in foot with passing "stable" callback to component below. Like, do you know if there is actual example somewhere, where things break? They (react devs) only talk about something concurrent, but no actual code, only hand waving potential dangers.