mirror of
https://github.com/streamich/react-use.git
synced 2026-02-01 14:37:31 +00:00
chore: clean tsconfig.json; feat: updated webpack config to export a function to achieve full-control mode, instead of deprecated Extend Mode;
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { storiesOf } from '@storybook/react';
|
|
import * as React from 'react';
|
|
import { useCopyToClipboard } from '../src';
|
|
import ShowDocs from './util/ShowDocs';
|
|
|
|
const Demo = () => {
|
|
const [text, setText] = React.useState('');
|
|
const [state, copyToClipboard] = useCopyToClipboard();
|
|
|
|
return (
|
|
<div>
|
|
<input value={text} onChange={e => setText(e.target.value)} />
|
|
<button type="button" onClick={() => copyToClipboard(text)}>
|
|
copy text
|
|
</button>
|
|
{state.error ? (
|
|
<p>Unable to copy value: {state.error.message}</p>
|
|
) : (
|
|
state.value && (
|
|
<>
|
|
<p>
|
|
Copied {state.value} {state.noUserInteraction ? 'without' : 'with'} user interaction
|
|
</p>
|
|
<input type="text" placeholder="Paste it in here to check" />
|
|
</>
|
|
)
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
storiesOf('Side-effects|useCopyToClipboard', module)
|
|
.add('Docs', () => <ShowDocs md={require('../docs/useCopyToClipboard.md')} />)
|
|
.add('Demo', () => <Demo />);
|