use-screenshot-to-clipboard
TypeScript icon, indicating that this package has built-in type declarations

1.0.9 • Public • Published

use-screenshot-to-clipboard

Make clipboard image from React Element

NPM JavaScript Style Guide

Install

npm install --save use-screenshot-to-clipboard

or

yarn add --save use-screenshot-to-clipboard

Usage

import React from 'react';
import { useRef } from 'react';
import { useScreenshotToClipboard, useScreenshot } from 'use-screenshot-to-clipboard';

const makeId = length => {
    let result = '';
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    const charactersLength = characters.length;
    let counter = 0;
    while (counter < length) {
        result += characters.charAt(Math.floor(Math.random() * charactersLength));
        counter += 1;
    }
    return result;
};

const App = () => {
    const ref = useRef(null);
    const [makeCopyToClipboard, _] = useScreenshotToClipboard({ quality: 1 });
    const [takeScreenShot, __] = useScreenshot({ quality: 1 });
    return (
        <>
            <div className='wrapper' ref={ref}>
                <table className='styled-table'>
                    <thead>
                        <tr>
                            <th>Name</th>
                            <th>Points</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>Dom</td>
                            <td>6000</td>
                        </tr>
                        <tr className='active-row'>
                            <td>Melissa</td>
                            <td>5150</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <button className='glow-on-hover' type='button' onClick={() => makeCopyToClipboard(ref.current)}>
                makeCopyToClipboard
            </button>
            <button
                className='glow-on-hover btn-right'
                type='button'
                onClick={() => takeScreenShot(ref.current, makeId(8))}
            >
                takeScreenShot
            </button>
        </>
    );
};
export default App;

License

MIT © tqvuong


This hook is created using create-react-hook.

Readme

Keywords

Package Sidebar

Install

npm i use-screenshot-to-clipboard

Weekly Downloads

0

Version

1.0.9

License

MIT

Unpacked Size

652 kB

Total Files

41

Last publish

Collaborators

  • tqvuongit