elements
lifecycle
browser
- useAudio
- useBattery
- useBluetooth
- useBreakpoints
- useBroadcastChannel
- useBrowserLocation
- useClipboard
- useCopy
- useCssVar
- useDisplayMedia
- useDocumentEvent
- useDocumentTitle
- useDocumentVisibility
- useEventListener
- useEventSource
- useEyeDropper
- useFavicon
- useFileSystemAccess
- useFps
- useFullscreen
- useGamepad
- useGeolocation
- useMeasure
- useMediaControls
- useMediaQuery
- useMemory
- useNetwork
- useObjectUrl
- useOnline
- useOtpCredential
- usePermission
- usePictureInPicture
- usePointerLock
- usePostMessage
- useRaf
- useShare
- useSpeechRecognition
- useSpeechSynthesis
- useSticky
- useVibrate
- useVirtualKeyboard
- useWakeLock
- useWebSocket
utilities
state
- useBoolean
- useControllableState
- useCookie
- useCookies
- useCounter
- useCycleList
- useDefault
- useDisclosure
- useField
- useHash
- useList
- useLocalStorage
- useMap
- useMask
- useMergedRef
- useObject
- useOffsetPagination
- useQueue
- useRafState
- useRefState
- useSessionStorage
- useSet
- useStateHistory
- useStep
- useStorage
- useToggle
- useUrlSearchParam
- useUrlSearchParams
- useValidatedState
- useWizard
user
sensors
- useDeviceMotion
- useDeviceOrientation
- useHotkeys
- useIdle
- useInfiniteScroll
- useIntersectionObserver
- useKeyboard
- useKeyPress
- useKeysPressed
- useMouse
- useMutationObserver
- useOrientation
- usePageLeave
- useParallax
- usePerformanceObserver
- useResizeObserver
- useScroll
- useScrollIntoView
- useScrollTo
- useSwipe
- useTextSelection
- useVisibility
- useWindowEvent
- useWindowFocus
- useWindowScroll
- useWindowSize
Share with friends
Spread the word about reactuse. Click the button below to copy the link to your clipboard and share it with anyone.
Star us on GitHub
import { useClipboard, useDisclosure } from '@siberiacancode/reactuse';
import { CheckIcon, CopyIcon } from 'lucide-react';
import { createPortal } from 'react-dom';
const SHARE_URL = 'https://reactuse.org';
const Demo = () => {
const clipboard = useClipboard();
const toast = useDisclosure();
const onShare = () => {
if (toast.opened) return;
clipboard.copy(SHARE_URL);
toast.open();
setTimeout(toast.close, 1500);
};
return (
<section className='flex max-w-sm flex-col gap-5'>
<div className='flex flex-col items-center gap-2'>
<h3>Share with friends</h3>
<p className='text-muted-foreground text-center text-sm'>
Spread the word about <b>reactuse</b>. Click the button below to copy the link to your
clipboard and share it with anyone.
</p>
</div>
<div className='relative mt-2 flex items-center gap-2'>
<input readOnly className='text-md! h-12! rounded-full! px-3!' value={SHARE_URL} />
<button className='absolute top-2 right-2 h-8!' type='button' onClick={onShare}>
<CopyIcon className='size-4' /> Share
</button>
</div>
<p className='text-muted-foreground text-center text-xs'>
Star us on{' '}
<a
className='underline'
href='https://github.com/siberiacancode/reactuse'
rel='noreferrer'
target='_blank'
>
GitHub
</a>
</p>
{toast.opened &&
createPortal(
<div className='animate-in fade-in slide-in-from-bottom-4 fixed right-4 bottom-6 left-4 flex items-center gap-3 rounded-2xl border border-black/5 bg-white px-4 py-3.5 text-sm font-medium text-gray-900 shadow-xl duration-300 sm:right-6 sm:left-auto sm:w-auto sm:min-w-72 dark:border-white/10 dark:bg-neutral-900 dark:text-white'>
<div className='flex size-6 shrink-0 items-center justify-center rounded-full bg-gray-900 dark:bg-white'>
<CheckIcon className='size-3.5 text-white dark:text-gray-900' />
</div>
Copied to clipboard!
</div>,
document.body
)}
</section>
);
};
export default Demo;
This hook uses navigator.clipboard browser api to provide enhanced functionality. Make sure to check for compatibility with different browsers when using this api
Installation
pnpm add @siberiacancode/reactuseUsage
const { value, copy } = useClipboard();Type Declarations
export interface UseCopyToClipboardReturn {
/** The copied value */
value: string | null;
/** Function to copy to clipboard */
copy: (value: string) => Promise<void>;
}
export interface UseCopyToClipboardParams {
/** Whether the copy to clipboard is enabled */
enabled: boolean;
}API
Parameters
| Name | Type | Default | Note |
|---|---|---|---|
| params.enabled | boolean | false | Whether the copy to clipboard is enabled |
Returns
UseCopyToClipboardReturnContributors
ddebabinNNursultan Zianurov
Last updated on