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
Would it be possible to create use_context_with::<T, R>(observer: impl FnOnce(&T) -> R) -> R to avoid Cloneing the context for every component (as with use_context)?
I have a context struct with tons of callbacks, settings, etc. and I'm trying to avoid adding an Rc when I simply need to access one field out of it:
Note 2: This probably couldn't prevent all instances of Cloneing contexts, e.g. when rendering child components. However, if a component re-renders for reasons unrelated to a particular context, it would be nice to avoid Cloneing that context.
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
-
Would it be possible to create
use_context_with::<T, R>(observer: impl FnOnce(&T) -> R) -> R
to avoidClone
ing the context for every component (as withuse_context
)?I have a context struct with tons of callbacks, settings, etc. and I'm trying to avoid adding an
Rc
when I simply need to access one field out of it:I see a few alternatives, all of which are undesirable:
Rc<LargeStruct>
in my context seems like overkill when only a small part of the context can be copied outNote: I posted on Discord before here: https://discord.com/channels/701068342760570933/703449306497024049/1020188734488055818
Note 2: This probably couldn't prevent all instances of
Clone
ing contexts, e.g. when rendering child components. However, if a component re-renders for reasons unrelated to a particular context, it would be nice to avoidClone
ing that context.Beta Was this translation helpful? Give feedback.
All reactions