Open wiseaidev opened 10 months ago
This seems like a nice first issue, im open to picking this up if you guys agree. Will probably require some generics and working with traits but am open to the challenge
@wiseaidev after having a look it seems pretty complex. We could make it work by giving an empty closure as the dispatch function but would not achieve much since you can just do that on your side instead and pass a default show_alert
closure instead of a UseStateHandler
. The opaque type comes from the hook macro which allows the reducers to access the HookContext
which gets created when the function component is created. Since this is props im not sure that can be instantiated before then and is why hooks must be called inside the fc.
The usecase might not be important enough for its complexity (if it is complex). It feels like there might be a way to do it but will have to wait for more guidance from someone a bit more experience with the codebase.
Problem:
While working on
yew-alert
, I noticed thatstd::default::Default
is not implemented foryew::UseStateHandle
. This could be beneficial when implementing theDefault
trait for a component'sProps
. For instance, in the case ofAlertProps
, it would resemble:This functionality is useful for allowing users to initialize the props struct by only passing some of the props values, with the others set to default, like so:
And then consume it in a component like so:
The same should apply to the
prop_or
attribute:Steps To Reproduce:
Attempt to implement
Default
for props containing aUseStateHandle
field type.Expected Behavior:
The
UseStateHandle
struct should have an implementation of theDefault
trait.Environment:
wasm32-unknown-unknown
Questionnaire: