use_clipboard

Function use_clipboard 

Source
pub fn use_clipboard() -> UseClipboardReturn<impl Fn(&str) + Clone + Send + Sync>
Expand description

Reactive Clipboard API.

Provides the ability to respond to clipboard commands (cut, copy, and paste) as well as to asynchronously read from and write to the system clipboard. Access to the contents of the clipboard is gated behind the Permissions API. Without user permission, reading or altering the clipboard contents is not permitted.

§Demo

Link to Demo

§Usage

let UseClipboardReturn { is_supported, text, copied, copy } = use_clipboard();

view! {
    <Show
        when=move || is_supported.get()
        fallback=move || view! { <p>Your browser does not support Clipboard API</p> }
    >
        <button on:click={
            let copy = copy.clone();
            move |_| copy("Hello!")
        }>
            <Show when=move || copied.get() fallback=move || "Copy">
                "Copied!"
            </Show>
        </button>
    </Show>
}

§SendWrapped Return

The returned closures copy is a sendwrapped function. It can only be called from the same thread that called use_clipboard.

§Server-Side Rendering

Make sure you follow the instructions in Server-Side Rendering.

On the server the returnd text signal will always be None and copy is a no-op.