Skip to content

Move React hooks out of component modules#7942

Open
joshblack wants to merge 2 commits into
joshblack/eslint-react-refresh/fix-hooks-and-barrelsfrom
joshblack/eslint-react-refresh/fix-hooks
Open

Move React hooks out of component modules#7942
joshblack wants to merge 2 commits into
joshblack/eslint-react-refresh/fix-hooks-and-barrelsfrom
joshblack/eslint-react-refresh/fix-hooks

Conversation

@joshblack

@joshblack joshblack commented Jun 8, 2026

Copy link
Copy Markdown
Member

Closes #

No linked issue.

Moves exported React hooks and shared Tabs state out of component implementation files so component modules can satisfy React Refresh component-only exports.

Changelog

New

  • Added ConfirmationDialog/useConfirm.ts.
  • Added ThemeContext.ts and useTheme.ts for Primer React theme state access.
  • Added experimental Tabs context, hook, and shared type modules.

Changed

  • Updated ConfirmationDialog tests/stories and root exports to import hooks from the new hook modules.
  • Updated experimental Tabs exports so hooks come from useTab, useTabList, and useTabPanel modules.

Removed

  • Removed hook exports from React component implementation files.

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; internal file organization only, with public exports preserved.

Testing & Reviewing

Review that hook modules follow use{Name}.ts naming and that Tabs component behavior is unchanged.

Merge checklist

@changeset-bot

changeset-bot Bot commented Jun 8, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f076444

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions Bot added staff Author is a staff member integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Jun 8, 2026
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

⚠️ Action required

👋 Hi, this pull request contains changes to the source code that github/github-ui depends on. If you are GitHub staff, test these changes with github/github-ui using the integration workflow. Check the integration testing docs for step-by-step instructions. Or, apply the integration-tests: skipped manually label to skip these checks.

To publish a canary release for integration testing, apply the Canary Release label to this PR.

@joshblack joshblack changed the title joshblack/eslint react refresh/fix hooks Move React hooks out of component modules Jun 8, 2026
@joshblack joshblack added skip changeset This change does not need a changelog integration-tests: skipped manually Changes in this PR do not require an integration test labels Jun 8, 2026
@joshblack joshblack marked this pull request as ready for review June 8, 2026 17:37
@joshblack joshblack requested a review from a team as a code owner June 8, 2026 17:37
@joshblack joshblack requested review from Copilot and jonrohan June 8, 2026 17:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors Primer React exports to satisfy React Refresh “component-only exports” expectations by moving hook implementations (and shared experimental Tabs state/types) out of component modules while preserving the public root exports.

Changes:

  • Added standalone theme hook/context modules (useTheme.ts, ThemeContext.ts) and updated ThemeProvider consumers to import hooks from the new module.
  • Extracted experimental Tabs hook logic/context/types into dedicated modules and adjusted experimental/Tabs exports accordingly.
  • Extracted useConfirm into ConfirmationDialog/useConfirm.ts and updated imports/exports, tests, and stories.
Show a summary per file
File Description
packages/react/src/useTheme.ts New module exporting useTheme/useColorSchemeVar hooks separate from ThemeProvider.
packages/react/src/ThemeProvider.tsx Uses extracted ThemeContext + useTheme from new module; stops exporting hooks.
packages/react/src/ThemeContext.ts New shared ThemeProvider context module.
packages/react/src/stories/ThemeProvider.stories.tsx Updates story imports to use the new useTheme module.
packages/react/src/index.ts Re-exports theme hooks from useTheme and useConfirm from its new module.
packages/react/src/experimental/Tabs/useTabs.ts New internal hook for accessing Tabs context.
packages/react/src/experimental/Tabs/useTabPanel.ts New extracted useTabPanel hook module.
packages/react/src/experimental/Tabs/useTabList.ts New extracted useTabList hook module.
packages/react/src/experimental/Tabs/useTab.ts New extracted useTab hook module.
packages/react/src/experimental/Tabs/types.ts New shared types for Tabs component + hooks.
packages/react/src/experimental/Tabs/TabsContext.ts New Tabs context module.
packages/react/src/experimental/Tabs/Tabs.tsx Keeps components in module; imports hooks/context/types from new modules.
packages/react/src/experimental/Tabs/Tabs.examples.stories.tsx Updates imports to use extracted Tabs hooks.
packages/react/src/experimental/Tabs/index.ts Re-exports Tabs component and hooks/types from their new modules.
packages/react/src/ConfirmationDialog/useConfirm.ts New extracted useConfirm hook module.
packages/react/src/ConfirmationDialog/ConfirmationDialog.tsx Removes hook implementation; leaves component-only exports.
packages/react/src/ConfirmationDialog/ConfirmationDialog.test.tsx Updates test imports to use extracted useConfirm.
packages/react/src/ConfirmationDialog/ConfirmationDialog.features.stories.tsx Updates story imports to use extracted useConfirm.
packages/react/src/tests/ThemeProvider.test.tsx Updates test imports to use new useTheme module.

Copilot's findings

  • Files reviewed: 19/19 changed files
  • Comments generated: 2

Comment on lines +87 to +90
export type TabListHookProps<T extends HTMLElement> = TabListProps & {
/** Optional ref to use for the tablist. If none is provided, one will be generated automatically */
ref?: React.RefObject<T>
}
Comment on lines +9 to +12

const onKeyDown = (event: React.KeyboardEvent) => {
const {current: tablist} = ref
if (tablist === null) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm integration-tests: skipped manually Changes in this PR do not require an integration test skip changeset This change does not need a changelog staff Author is a staff member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants