Skip to content

Commit 45f961e

Browse files
childrentimeclaude
andcommitted
fix(useClipboard): use defaultWindow instead of window for SSR safety
The focus event listener was directly referencing `window`, which throws ReferenceError in SSR environments. Use `defaultWindow` which safely returns undefined in non-browser contexts. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9d89977 commit 45f961e

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@reactuses/core",
3-
"version": "6.3.0",
3+
"version": "6.3.1",
44
"description": "Collection of 100+ essential React Hooks with TypeScript support, tree-shaking, and SSR compatibility. Sensors, browser APIs, state management, animations, and more.",
55
"license": "Unlicense",
66
"homepage": "https://www.reactuse.com/",

packages/core/src/useClipboard/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useCallback, useEffect, useState } from 'react'
22
import { useEventListener } from '../useEventListener'
3+
import { defaultWindow } from '../utils/browser'
34
import type { UseClipboard } from './interface'
45

56
export const useClipboard: UseClipboard = (): readonly [
@@ -28,7 +29,7 @@ export const useClipboard: UseClipboard = (): readonly [
2829
useEventListener('cut', updateText)
2930

3031
// Also listen for focus events to update clipboard when window regains focus
31-
useEventListener('focus', updateText, window)
32+
useEventListener('focus', updateText, defaultWindow)
3233

3334
const copy = useCallback(async (txt: string) => {
3435
setText(txt)

0 commit comments

Comments
 (0)