react-copy-to-clipboard

A tiny React component that wraps any element to copy text to the clipboard on click.

Library
npm
v5.1.1
2,369stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
44/100Fair
Development Activity4
Maintenance20
Community52
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
46/100Fair
Architecture60
Code Quality48
Innovation30
Learning Curve45

react-copy-to-clipboard is a minimal React wrapper component that adds copy-to-clipboard behavior to any single child element — a button, span, or icon — without dictating its markup or styling. It delegates the actual clipboard write to the battle-tested copy-to-clipboard package, which layers execCommand, the IE-specific clipboardData interface, and a prompt-based fallback so the copy action works across a wide range of browsers.

Rather than rendering its own DOM node, the component clones its single child and attaches an onClick handler, preserving any onClick the child already had. An optional onCopy(text, result) callback reports whether the copy succeeded, making it easy to drive UI feedback like a “Copied!” message. With one required text prop and just two runtime dependencies, it’s a drop-in solution for apps that need copy-to-clipboard buttons without reimplementing the browser-compatibility logic themselves.

What You Get

  • A CopyToClipboard component that wraps a single child element and adds click-to-copy behavior
  • Cross-browser clipboard writes via the underlying copy-to-clipboard package (execCommand, IE clipboardData, prompt fallback)
  • An onCopy(text, result) callback reporting the copied text and whether the write succeeded
  • Pass-through of any existing onClick handler and other props on the wrapped child
  • Support for copy-to-clipboard options like debug, message, and format

Common Use Cases

  • Adding a Copy button next to a code snippet, API key, or shareable link
  • Copying auto-generated text such as invite codes, coupon codes, or share URLs with a single click
  • Building ‘copied!’ confirmation UI in forms or dashboards
  • Wrapping icon buttons in documentation sites for one-click code copy

Under The Hood

Architecture The entire public surface is a single component, CopyToClipboard in src/Component.js, exported through src/index.js (which re-attaches it as a named property for CJS/ESM interop). It’s a React.PureComponent with no internal state: on click it calls copy(text, options) from the copy-to-clipboard package, invokes an optional onCopy(text, result) callback, then forwards the event to the wrapped child’s own onClick if one was already present. Rendering uses React.Children.only(children) plus React.cloneElement to attach the handler without introducing an extra DOM node, so the component’s entire contract is “clone the one child you give me.” Because that’s the whole abstraction, any change to the clone/wrap mechanism would break every consumer at once — there’s no internal layering to insulate them from it.

Tech Stack Built for React (peerDependencies: react >=15.3.0) with Babel (@babel/preset-env, @babel/preset-react) compiling src/ to a CommonJS lib/ output for publishing. Webpack 5 builds three variants of the demo/dist bundles (dev, dist, min, pub) for the GitHub Pages example. Biome replaces the older ESLint/Prettier combo for linting and formatting, Yarn 4 (Berry) is the package manager, and CircleCI runs the install/lint/test pipeline. Runtime dependencies are limited to copy-to-clipboard (the actual clipboard-write logic) and prop-types.

Code Quality The active test file (test/Component-test.js) only asserts that CopyToClipboard is a function — the substantial suite covering click behavior, onCopy invocation, and prop pass-through is present but entirely commented out, referencing an older TestUtils/DOM-rendering approach that was never ported to the current cloneElement-based implementation. So today there is effectively no behavioral test coverage, despite tape being wired up as the test runner. There’s no TypeScript; type safety comes only from PropTypes declarations on text, children, onCopy, and options. Naming and file layout are clean and consistent, and Biome plus a CircleCI pipeline are configured, but the lack of working tests is a real gap for a component this widely depended upon.

What Makes It Unique The library isn’t technically novel — it’s a thin, declarative wrapper around the copy-to-clipboard package’s imperative API, trading a few bytes of abstraction for React idiom (a component you wrap children in, rather than a function you call in an event handler). Its value is ergonomic simplicity and broad, well-tested browser fallback behavior inherited from its dependency, not any new technique of its own.

Used by 9 apps in this directory

Go
49%
Other

Cosmos-Server

Security · Authentication

6,146

All-in-one self-hosted home server with SmartShield anti-DDoS, Nebula mesh VPN, automatic HTTPS, and a 250-app marketplace — all secured behind a unified auth layer.

View details
85
Repo Health
59
Technical
64
Dependency
Built with
Go49%
JavaScript48%
Updated 2 days ago
TypeScript
95%
AGPL 3.0

HeyForm

Forms Surveys · No Code Platforms

8,965

Open-source conversational form builder with AI generation, conditional logic, and 30+ integrations — self-host with full data ownership.

View details
85
Repo Health
67
Technical
67
Dependency
Built with
TypeScript95%
Updated 1 weeks ago
TypeScript
71%
Other

highlight.io

Developer Tools · Analytics · Monitoring

9,372

Open-source full-stack monitoring that unifies session replay, error tracking, logging, and distributed tracing so you can stop context-switching between tools.

View details
69
Repo Health
78
Technical
65
Dependency
Built with
TypeScript71%
Go16%
Updated 2 weeks ago
TypeScript
96%
MIT

HyperDX

Developer Tools · Analytics · Monitoring

9,873

Open source observability platform that unifies logs, traces, metrics, and session replays on ClickHouse — now the core of ClickStack.

View details
88
Repo Health
83
Technical
68
Dependency
Built with
TypeScript96%
Updated yesterday
Python
84%
MIT

LiteLLM

AI Development · Developer Tools

58,169

Open source AI gateway and Python SDK that gives you one OpenAI-compatible interface to call 100+ LLM providers, with built-in routing, cost tracking, guardrails, and virtual keys.

View details
92
Repo Health
81
Technical
69
Dependency
Built with
Python84%
TypeScript13%
Updated today
TypeScript
71%
Apache 2.0

Supabase

Developer Tools · Databases · Search

108,912

The open-source Postgres development platform that replaces Firebase with authentication, real-time APIs, edge functions, storage, and vector embeddings — all built on PostgreSQL.

View details
90
Repo Health
91
Technical
62
Dependency
Built with
TypeScript71%
MDX26%
Updated today
JavaScript
94%
Apache 2.0

swagger-ui

Developer Tools

29,002

Transform OpenAPI specifications into interactive, browser-based API documentation that developers and consumers can explore and test live.

View details
97
Repo Health
83
Technical
65
Dependency
Built with
JavaScript94%
Updated 2 days ago
JavaScript
55%
AGPL 3.0

ToolJet

Low Code Platforms · No Code Platforms · AI Agents

40,857

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
JavaScript55%
TypeScript38%
Updated today
Go
75%
AGPL 3.0

ZITADEL

Authentication

14,949

Open-source, API-first identity platform delivering multi-tenancy, Passkeys, OIDC, SAML, and SCIM without vendor lock-in.

View details
91
Repo Health
81
Technical
68
Dependency
Built with
Go75%
TypeScript12%
Updated 3 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search