`Copy` setters struct for hooks (instead of arc closure)
The UI code has these "clone blocks" everywhere right now:{ let set_some = set_some.clone(); move |_| set_some("test")}.
Leptos has solved this by instead of returning a closure from use_state (or create_signal in their case), they return a Copy struct, which looks like this: https://docs.rs/leptos_reactive/0.2.5/src/leptos_reactive/signal.rs.html#827
Would be interesting to explore if we could do something similar.
👋 We built a similar system for Dioxus and published it as a separate library: generational-box is similar to Leptos' copy sync system except:
- You can include your own reactivity system or not
- You can call the value like a function on stable
- You can read and write to the value directly instead of using
with_methods
@ealmloff Oh that looks awesome! Thanks for letting us know
@ealmloff Btw are there any plans for making EventHandler etc. use that? Would be ⭐amazing⭐ if it was possible to just move that around more freely
@ealmloff Btw are there any plans for making EventHandler etc. use that? Would be ⭐amazing⭐ if it was possible to just move that around more freely
That is something we have been discussing. We could make this version of event handlers copy. The issue is we would need to make the event handles 'static instead of using the bump lifetime which means you need to clone all non-signal hooks which would be very breaking. (It is the same as the issue discussed here https://discord.com/channels/899851952891002890/928812591126569000/1181770301827207258)