react-copy-to-clipboard-lite is a lightweight (approx. 1.1 kB minzipped), dependency-free utility for copying text to the clipboard in React applications, currently at version 1.0.3. It offers a tiered fallback mechanism, utilizing the modern Clipboard API first and gracefully falling back to `document.execCommand` for older browsers like Safari, without relying on deprecated `prompt()` calls for permissions. The library provides structured `CopyResult` objects for robust error handling and never throws exceptions. It is designed to be SSR-safe, permission-aware (checking `navigator.permissions.query()` without prompting), and fully supports React 18+ environments, including new React 19 features like `formAction` and `useActionState`. This package differentiates itself through its minimal footprint, lack of runtime dependencies, and explicit handling of permissions and SSR contexts.
npm install react-copy-to-clipboard-liteVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to use the `useCopyToClipboard` React hook to add copy-to-clipboard functionality to a button, including handling copy status and potential errors.
Change `import { CopyToClipboard } from "react-copy-to-clipboard"` to `import { CopyToClipboard } from "react-copy-to-clipboard-lite/react"` and similar for other modules.Ensure your application is served over HTTPS in production and use localhost for development to fully leverage the Clipboard API.
Consider providing UI feedback to users about clipboard permission status if granular control and user awareness are critical for your application.
Do not rely on `clearAfter` for sensitive data that requires absolute and guaranteed destruction from clipboard history. It's a convenience, not a security feature.
Ensure you are importing React hooks/components from the correct path: `import { useCopyToClipboard } from 'react-copy-to-clipboard-lite/react';`Access your application over HTTPS or use `localhost` during development to enable the Clipboard API.
This library does not prompt for permissions. You may need to instruct users to manually grant clipboard permissions in their browser settings for your domain.
Verify the package is installed (`npm install react-copy-to-clipboard-lite`) and ensure the import path `react-copy-to-clipboard-lite/react` is typed correctly.