How to implement "borrowed props" in dioxus 0.5? #3112
Unanswered
bluenote10
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Apparently older versions of dioxus had owned vs borrowed props, but version 0.5 removed the "borrowed props". The migration guide mentions that
ReadOnlySignal
can be used to approximate borrowed props.So far, my attempts at using
ReadOnlySignal
to get real borrowed props were not successful. Consider for instance the following example. Let's say our original code is:Imagine our logic to render an
entry
gets more complicated than a singlediv
. Then it would feel naturally to slightly refactor the code so move the (potentially verbose/messy) entry rendering into a separate function. Something like this:This is where I would like to use a borrowed prop for
Entry
. I.e., I would like to apply such a refactoring without having an impact on performance / memory usage. Essentially I would like theEntry
render function to just take aentry: &str
, but that doesn't compile. Surprisingly, using theReadOnlySignal
also requires to use.clone()
at the call site, which basically means that I could as well go forfn Entry(entry: String) -> ...
as well, no?How can I factor out such small "render helper components" without the need for owning / clone?
(In this example the
clone()
on aString
isn't particularly costly, but if these "entries" are more heavy-weight having to clone them everywhere feels pretty bad.)Beta Was this translation helpful? Give feedback.
All reactions