Skip to content

refactor(ui-react): split useCopy hook into its own file#6167

Open
luizhf42 wants to merge 1 commit intomasterfrom
refactor/ui-react/use-copy-hook
Open

refactor(ui-react): split useCopy hook into its own file#6167
luizhf42 wants to merge 1 commit intomasterfrom
refactor/ui-react/use-copy-hook

Conversation

@luizhf42
Copy link
Copy Markdown
Member

What

Move the useCopy hook and its ClipboardContext out of
ClipboardProvider.tsx into a dedicated hooks/useCopy.ts module.

Why

ClipboardProvider.tsx exported a component, a hook, and an interface
from the same file, tripping react-refresh/only-export-components:

warning  Fast refresh only works when a file only exports components

Beyond the lint noise, the mixed exports broke HMR for the provider —
editing it triggered a full reload instead of a fast refresh.

Changes

  • hooks/useCopy.ts: new home for ClipboardContext, its value type,
    and the useCopy hook. The context is exported so the provider can
    consume it.
  • ClipboardProvider.tsx: now a component-only module that imports
    ClipboardContext from @/hooks/useCopy.
  • CopyButton / CopyWarning / ClipboardProvider.test: import
    useCopy from @/hooks/useCopy instead of the provider file.

Testing

  • npm run lint — no react-refresh warning on ClipboardProvider.tsx
  • npx vitest run src/components/common/__tests__/ClipboardProvider.test.tsx src/components/common/__tests__/CopyWarning.test.tsx — 33 tests pass

Keeps ClipboardProvider.tsx as a component-only module so
react-refresh/only-export-components no longer warns, and lets HMR
fast-refresh the provider cleanly.
@luizhf42 luizhf42 requested a review from a team as a code owner April 13, 2026 19:01
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 13, 2026

Claude finished @luizhf42's task in 1m 9s —— View job


Code Review Complete

Reviewed 5 files across code quality, security, testing, language patterns, and architecture — no issues found. The code looks good as-is.

Summary: Clean mechanical refactoring that moves useCopy hook and ClipboardContext from ClipboardProvider.tsx into hooks/useCopy.ts. All import paths are correctly updated, no stale imports remain, the UseCopyResult interface is appropriately narrowed to non-exported (nothing depended on it), and the test file properly splits its imports between the two modules. This correctly fixes the react-refresh/only-export-components lint warning.


If you push additional changes and want a new review, tag @shellhub-io/admin and a team member can trigger it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant