Struct dioxus_core::prelude::EventHandler
source · [−]pub struct EventHandler<'bump, T = ()> {
pub callback: RefCell<Option<BumpBox<'bump, dyn FnMut(T) + 'bump>>>,
}
Expand description
The callback type generated by the rsx!
macro when an on
field is specified for components.
This makes it possible to pass move |evt| {}
style closures into components as property fields.
Example
ⓘ
rsx!{
MyComponent { onclick: move |evt| log::info!("clicked"), }
}
#[derive(Props)]
struct MyProps<'a> {
onclick: EventHandler<'a, MouseEvent>,
}
fn MyComponent(cx: Scope<'a, MyProps<'a>>) -> Element {
cx.render(rsx!{
button {
onclick: move |evt| cx.props.onclick.call(evt),
}
})
}
Fields
callback: RefCell<Option<BumpBox<'bump, dyn FnMut(T) + 'bump>>>
The (optional) callback that the user specified
Uses a RefCell
to allow for interior mutability, and FnMut closures.
Implementations
sourceimpl<T> EventHandler<'_, T>
impl<T> EventHandler<'_, T>
Trait Implementations
Auto Trait Implementations
impl<'bump, T = ()> !RefUnwindSafe for EventHandler<'bump, T>
impl<'bump, T = ()> !Send for EventHandler<'bump, T>
impl<'bump, T = ()> !Sync for EventHandler<'bump, T>
impl<'bump, T> Unpin for EventHandler<'bump, T>
impl<'bump, T = ()> !UnwindSafe for EventHandler<'bump, T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more