一个简单而灵活的React实用程序组件,用于将文本复制到剪贴板

网友投稿 651 2022-11-02

一个简单而灵活的React实用程序组件,用于将文本复制到剪贴板

一个简单而灵活的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 = () => ( } />)export default Demo;

Props

NameTypeDescriptionRequired
renderfunctionA function that returns a React element.Y
textstringThe text to be copied when copy is called.Y
propsobjectprops to pass to the component in renderN
onSuccessfunctionFunction called when copy succeeds.N
onErrorfunctionFunction 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小时内删除侵权内容。

上一篇:#yyds干货盘点# leetcode算法题:旋转图像
下一篇:Spring从入门到精通(十)—面试官:FactoryBean 和 BeanFactory有啥区别
相关文章

 发表评论

暂时没有评论,来抢沙发吧~