You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this REPL, I have an App component that has a signal with a value that is either a string or null. <App/> also renders the <ChildComponent/> component which uses that signal inside a useComputed() hook. ChildComponent is only rendered by App if the value of that signal is not null, which is checked inside another useComputed() hook.
With traditional useState()s such code works as expected because the entire component is re-rendered if the state changes. However, since signals bypass the usual re-render mechanism, it seems the computed hook in the child component gets updated anyway, even if that component is no longer shown by its parent.
I'm not sure if this is a bug, more likely I'm misunderstanding how I'm supposed to use signals.
My use case is that I have a signal defined in a parent that is used by several child components, and I only show those components if the signal is not null. Since I use useComputed() several times, doing null checks on each child component would be possible but impractical.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In this REPL, I have an App component that has a signal with a value that is either a string or null.
<App/>
also renders the<ChildComponent/>
component which uses that signal inside auseComputed()
hook. ChildComponent is only rendered by App if the value of that signal is not null, which is checked inside anotheruseComputed()
hook.With traditional
useState()
s such code works as expected because the entire component is re-rendered if the state changes. However, since signals bypass the usual re-render mechanism, it seems the computed hook in the child component gets updated anyway, even if that component is no longer shown by its parent.I'm not sure if this is a bug, more likely I'm misunderstanding how I'm supposed to use signals.
My use case is that I have a signal defined in a parent that is used by several child components, and I only show those components if the signal is not null. Since I use
useComputed()
several times, doing null checks on each child component would be possible but impractical.Beta Was this translation helpful? Give feedback.
All reactions