Skip to content

Latest commit

Β 

History

History
35 lines (27 loc) Β· 1.07 KB

useCopyToClipboard.md

File metadata and controls

35 lines (27 loc) Β· 1.07 KB

useCopyToClipboard

Copy text to a user's clipboard.

Usage

const Demo = {
    setup() {

        const [text] = useState('');
        const [state, copyToClipboard] = useCopyToClipboard();

        return () => (
            <div>
                <input v-model={text.value}/>
                <button type="button" onClick={() => copyToClipboard(text.value)}>copy text</button>
                {state.error
                    ? <p>Unable to copy value: {state.error.message}</p>
                    : state.value && <p>Copied {state.value}</p>}
            </div>
        )
    }
}

Reference

const [{value, error, noUserInteraction}, copyToClipboard] = useCopyToClipboard();
  • value β€” value that was copied to clipboard, undefined when nothing was copied.
  • error β€” caught error when trying to copy to clipboard.
  • noUserInteraction β€” boolean indicating if user interaction was required to copy the value to clipboard to expose full API from underlying copy-to-clipboard library.