-
-
Notifications
You must be signed in to change notification settings - Fork 124
useSignalEffect should execute after changes have been applied to the DOM #228
Copy link
Copy link
Closed
Description
The callback passed to useSignalEffect should be executed after the changes (if any) have been applied to the DOM. Otherwise, it won't be a direct replacement for useEffect.
For example, people expect this to work, even if ref appears when open switches from false to true, because useEffect waits until changes have been applied to the DOM:
useEffect(() => {
if (open) ref.current.focus();
}, [open]);But with the current implementation of useSignalEffect, the callback runs before the DOM changes, and therefore ref.current may not exist yet:
useSignalEffect(() => {
if (open.value) ref.current.focus();
});Other reactive libraries introduce a tick function (Vue, Svelte, Alpine), but I'd prefer if useSignalEffect could mimic useEffect because the familiarity and ergonomics are better. I.e., access to signals after the tick() call are not tracked.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels