npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

use-clipboard-history

v1.0.1

Published

A React hook for managing clipboard history with customizable UI components

Downloads

20

Readme

use-clipboard-history

A React hook for managing clipboard history with customizable UI components. Perfect for note apps, editors, admin dashboards, and anywhere users frequently copy and paste content.

Features

  • 📋 Clipboard History Management - Track and manage copied content
  • 🎨 Customizable UI Components - Pre-built components with modern styling
  • 💾 Persistent Storage - Optional localStorage persistence
  • 🔍 Search Functionality - Built-in search through clipboard history
  • 📱 Responsive Design - Works on desktop and mobile
  • 🔧 TypeScript Support - Full TypeScript definitions included
  • 🚀 Lightweight - No heavy dependencies, just React

Installation

npm install use-clipboard-history
# or
yarn add use-clipboard-history

Quick Start

Basic Usage

import React from 'react';
import { useClipboardHistory } from 'use-clipboard-history';

function MyComponent() {
  const { history, copyToClipboard, addToHistory } = useClipboardHistory();

  const handleCopy = async (text: string) => {
    await copyToClipboard(text);
    // Content is automatically added to history
  };

  return (
    <div>
      <button onClick={() => handleCopy('Hello World!')}>
        Copy Text
      </button>
      
      <div>
        <h3>Clipboard History:</h3>
        {history.map(item => (
          <div key={item.id}>
            {item.content} - {new Date(item.timestamp).toLocaleString()}
          </div>
        ))}
      </div>
    </div>
  );
}

With Context Provider

import React from 'react';
import { 
  ClipboardHistoryProvider, 
  ClipboardHistoryWidget 
} from 'use-clipboard-history';

function App() {
  return (
    <ClipboardHistoryProvider 
      options={{
        maxItems: 100,
        persistToStorage: true,
        storageKey: 'my-app-clipboard',
      }}
    >
      <div>
        <h1>My App</h1>
        <ClipboardHistoryWidget />
      </div>
    </ClipboardHistoryProvider>
  );
}

API Reference

useClipboardHistory Hook

const {
  history,
  addToHistory,
  removeFromHistory,
  clearHistory,
  copyToClipboard,
  copyFromHistory,
  isSupported
} = useClipboardHistory(options);

Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | maxItems | number | 50 | Maximum number of items to keep in history | | persistToStorage | boolean | false | Whether to persist history to localStorage | | storageKey | string | 'use-clipboard-history' | Key for localStorage | | includeImages | boolean | false | Whether to include images in history | | includeFiles | boolean | false | Whether to include files in history | | autoCopy | boolean | false | Automatically track clipboard changes |

Return Values

| Property | Type | Description | |----------|------|-------------| | history | ClipboardItem[] | Array of clipboard items | | addToHistory | (content: string, type?: string, metadata?: object) => void | Add item to history | | removeFromHistory | (id: string) => void | Remove item from history | | clearHistory | () => void | Clear all history | | copyToClipboard | (content: string) => Promise<void> | Copy content and add to history | | copyFromHistory | (id: string) => Promise<void> | Copy item from history | | isSupported | boolean | Whether clipboard API is supported |

ClipboardHistoryProvider

Context provider for sharing clipboard history across components.

<ClipboardHistoryProvider options={options}>
  {children}
</ClipboardHistoryProvider>

ClipboardHistoryWidget

A complete UI component with search, clear functionality, and modern styling.

<ClipboardHistoryWidget
  maxHeight="400px"
  showSearch={true}
  showClearButton={true}
  showStats={true}
  placeholder="Search clipboard history..."
  emptyMessage="No clipboard history yet"
  maxContentLength={100}
/>

ClipboardHistoryList

A simpler list component for custom implementations.

<ClipboardHistoryList
  maxHeight="300px"
  showTimestamps={true}
  showRemoveButton={true}
  onItemClick={(id, content) => console.log('Clicked:', content)}
  emptyMessage="No items"
  maxContentLength={80}
/>

Advanced Examples

Custom UI Implementation

import React from 'react';
import { useClipboardHistoryContext } from 'use-clipboard-history';

function CustomClipboardUI() {
  const { history, copyFromHistory, removeFromHistory } = useClipboardHistoryContext();

  return (
    <div className="custom-clipboard-ui">
      {history.map(item => (
        <div key={item.id} className="clipboard-item">
          <span>{item.content}</span>
          <button onClick={() => copyFromHistory(item.id)}>
            Copy
          </button>
          <button onClick={() => removeFromHistory(item.id)}>
            Remove
          </button>
        </div>
      ))}
    </div>
  );
}

Note Taking App Example

import React, { useState } from 'react';
import { 
  ClipboardHistoryProvider, 
  ClipboardHistoryWidget,
  useClipboardHistoryContext 
} from 'use-clipboard-history';

function NoteEditor() {
  const [notes, setNotes] = useState<string[]>([]);
  const { addToHistory } = useClipboardHistoryContext();

  const addNote = (content: string) => {
    setNotes(prev => [...prev, content]);
    addToHistory(content, 'text', { source: 'note-editor' });
  };

  return (
    <div style={{ display: 'flex', gap: '20px' }}>
      <div style={{ flex: 1 }}>
        <textarea 
          placeholder="Write your notes..."
          onChange={(e) => addNote(e.target.value)}
        />
      </div>
      <div style={{ width: '300px' }}>
        <ClipboardHistoryWidget />
      </div>
    </div>
  );
}

function NoteApp() {
  return (
    <ClipboardHistoryProvider options={{ persistToStorage: true }}>
      <NoteEditor />
    </ClipboardHistoryProvider>
  );
}

Admin Dashboard Example

import React from 'react';
import { 
  ClipboardHistoryProvider, 
  ClipboardHistoryWidget 
} from 'use-clipboard-history';

function AdminDashboard() {
  return (
    <div className="admin-dashboard">
      <header>
        <h1>Admin Dashboard</h1>
      </header>
      
      <div className="dashboard-content">
        <div className="sidebar">
          <ClipboardHistoryWidget 
            maxHeight="600px"
            showSearch={true}
            showStats={true}
            placeholder="Search copied content..."
          />
        </div>
        
        <div className="main-content">
          {/* Your dashboard content */}
        </div>
      </div>
    </div>
  );
}

function App() {
  return (
    <ClipboardHistoryProvider 
      options={{
        maxItems: 200,
        persistToStorage: true,
        storageKey: 'admin-clipboard-history',
      }}
    >
      <AdminDashboard />
    </ClipboardHistoryProvider>
  );
}

Browser Support

This package uses the modern Clipboard API with fallbacks for older browsers:

  • ✅ Chrome 66+
  • ✅ Firefox 63+
  • ✅ Safari 13.1+
  • ✅ Edge 79+

For older browsers, the package falls back to the document.execCommand('copy') method.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License - see the LICENSE file for details.