前端框架选型是企业提升开发效率与用户体验的关键因素
651
2022-11-02
一个简单而灵活的React实用程序组件,用于将文本复制到剪贴板
Simple React Clipboard
A simple and flexible React utility component for copying texts to the clipboard. Demo and sample code here.
Why This?
Existing React clipboard libraries are restrictive (e.g. you can only trigger copy on click / you must render a button or a span). Simple React Clipboard allows you to trigger copy whenever and however you want, with whatever component that fits your use case.
Getting Started
npm i simple-react-clipboard
The component passed in the render prop will have the copy function passed in as a prop. The copy function will copy the text prop to the clipboard.
import React from "react";import Clipboard from "simple-react-clipboard";const Demo = () => (
Props
Name | Type | Description | Required |
---|---|---|---|
render | function | A function that returns a React element. | Y |
text | string | The text to be copied when copy is called. | Y |
props | object | props to pass to the component in render | N |
onSuccess | function | Function called when copy succeeds. | N |
onError | function | Function called when copy fails. | N |
To Run this Repository
git clone https://github.com/donfour/simple-react-clipboard.gitnpm installnpm run dev
To Test this Repository
npm run test
Credits
This package is based on the awesome clipboard.js.
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~