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
Many callbacks don't require state specific to a particular call to view, so it makes sense to store them on a component, similar to use_callback in the functional component case, so that they compare equal and don't trigger props changes in children.
I have been doing this by declaring a field in the struct component of type Callback, and then populating it during create. However I know that Callback works by cloning the Scope and moving it into the Callback, so my struct will then contain an owned reference to its own Scope.
My question is, does storing a clone of the component's Scope within a struct component create a reference cycle and prevent the struct component from being destructed, or is storing a component's own scope within it normal/acceptable.
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
-
Many callbacks don't require state specific to a particular call to
view
, so it makes sense to store them on a component, similar touse_callback
in the functional component case, so that they compare equal and don't trigger props changes in children.I have been doing this by declaring a field in the struct component of type
Callback
, and then populating it duringcreate
. However I know thatCallback
works by cloning theScope
and moving it into theCallback
, so my struct will then contain an owned reference to its ownScope
.My question is, does storing a clone of the component's
Scope
within a struct component create a reference cycle and prevent the struct component from being destructed, or is storing a component's own scope within it normal/acceptable.E.g.
Beta Was this translation helpful? Give feedback.
All reactions