Daily quality NPM Package replication _copy-to-clipboard

Source: Internet
Author: User

First, Copy-to-clipboard

Official definition: Simple module exposing copy function

Understanding: A Super simple copy function, and this method is suitable for triggering the replication function through other events

What do you mean? For example: I want to design a copy of the selection when the select selection changes, it is generally not possible to insert the component (and so on will introduce a react replication component of NPM), this time is copy-to-clipboard very appropriate. It's very reasonable to use it for simplicity, of course.

Usage
import copy from ‘copy-to-clipboard‘;//最简单用法copy(‘你要复制的文本‘)

Just use it. It's a little too simple. It is usually necessary to notify the user after the successful replication, but there is no callback function, how to implement?

Two ways to solve:

    1. The author is thoughtful and copy will actually return a Boolean value, that is, the copy returns true successfully, otherwise false

Author's official definition: copy(text: string, options: object): boolean -tries to copy text to Clipboard.

Example:

copy(‘复制文本‘) && message.success(`复制成功`)

Of course this is because my project already has a UI framework, and I'm using the framework's API tips

    1. Recommended tips for official use prompt

copyReceive two parameters:debug and message
Let's take a look at these two parameters. Official definitions
Value | Default | Notes
:--: | :--: | :--:
Debug | False | Boolean. Optional. Enable output to console.
message | Copy to clipboard: #{key}, Enter | String. Optional. Prompt message. *

Debug: Optional parameter. Start the console output.

I'm not quite sure what this description means. Automatically output to the console? I tried it and it didn't happen. Even if set to false, it can still be copied. Leave a hole in here.

message: Optional parameter. Prompt message.

copy(‘Text‘, {  message: ‘Copy to clipboard #{key}‘,});

Second, more replication function class NPM Package
    • "React-copy-to-clipboard"

This copy-to-clipboard is more than a function, but it is based on the react component development, can be selected according to the specific situation

    • "Copy-button"

Daily quality NPM package replication _copy-to-clipboard

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.