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:
- 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
- Recommended tips for official use
prompt
copy
Receive 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
Daily quality NPM package replication _copy-to-clipboard