pub fn use_drag_with_options<'hook>(
node: NodeRef,
options: UseDragOptions,
) -> impl 'hook + Hook<Output = UseDragHandle>
Expand description
This hook tracks file, link and copy-paste drags.
use_drag
hook with options.
§Example
use yew_hooks::prelude::*;
#[function_component(UseDrag)]
fn drag() -> Html {
let node = use_node_ref();
let state = use_drag_with_options(node.clone(), UseDragOptions {
ondragstart: Some(Box::new(move |e| {
if let Some(data_transfer) = e.data_transfer() {
let _ = data_transfer.set_data("text", "hello");
}
})),
ondragend: Some(Box::new(move |e| {
})),
});
html! {
<div ref={node}>
<p>
<b>{ " Dragging: " }</b>
{ *state.dragging }
</p>
<p>
{ "Try to drag this area" }
</p>
</div>
}
}
§Note
When used in function components and hooks, this hook is equivalent to:
pub fn use_drag_with_options(node: NodeRef, options: UseDragOptions) -> UseDragHandle {
/* implementation omitted */
}