Skip to content

Update React imports to use destructuring #65

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged

Conversation

nicodes
Copy link
Collaborator

@nicodes nicodes commented Jun 11, 2025

Attempt to fix https://github.com/github/spark/issues/1107

This changes all the react imports to use destructuring rather than * as React. This will hopefully no longer give use the UseContext error

@Copilot Copilot AI review requested due to automatic review settings June 11, 2025 18:06
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors all UI component wrappers to use destructured React imports and ComponentProps instead of React.ComponentProps, and updates React hooks and context APIs to their named imports.

  • Swap import * as React for named imports (ComponentProps, hooks, etc.)
  • Replace React.X usages with direct calls (useContext, createContext, useId, etc.)
  • Update type references (ReactNodeReactNode, React.CSSPropertiesCSSProperties, React.ComponentTypeComponentType)

Reviewed Changes

Copilot reviewed 47 out of 47 changed files in this pull request and generated no comments.

File Description
src/components/ui/form.tsx Swapped React namespace imports for named imports
src/components/ui/**/*.tsx Applied same import and hook refactoring across files
src/components/ui/chart.tsx Added additional React types (ReactNode, CSSProperties)
src/components/ui/carousel.tsx Imported useState, useEffect, useCallback, etc.
Comments suppressed due to low confidence (1)

src/components/ui/button.tsx:44

  • [nitpick] The wrapper components for Radix primitives and other UI elements repeat the same boilerplate pattern. Consider creating a small factory or higher-order function to generate these wrappers automatically, reducing duplication and easing future updates.
}: ComponentProps<"button"> &

@nicodes nicodes merged commit ffa0d3f into main Jun 11, 2025
3 checks passed
@nicodes nicodes deleted the nicodes/fix-react-imports branch June 11, 2025 18:30
Copy link
Contributor

@ansballard ansballard left a comment

Choose a reason for hiding this comment

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

The imports across this template are just a little... weird. No type imports, but those have been around for a while. And looking around a bit I'm wondering if the import * as React was because the jsx-runtime wasn't being used, so React had to be imported anywhere there was jsx. Maybe this is a remnant of some AI generated components from a model trained on older react code?

Regardless if we're hitting bundler weirdness, standardizing our imports seems like a really good thing to work on

@@ -1,28 +1,28 @@
"use client"

import * as React from "react"
import { ComponentProps } from "react"
Copy link
Contributor

Choose a reason for hiding this comment

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

all these ComponentProps imports should be type imports, right? Shouldn't matter functionally but I'm not sure if it would bloat the bundle

@@ -1,6 +1,6 @@
"use client"

import * as React from "react"
import { ComponentProps, createContext, useCallback, useContext, useEffect, useState, KeyboardEvent } from "react"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { ComponentProps, createContext, useCallback, useContext, useEffect, useState, KeyboardEvent } from "react"
import { type ComponentProps, createContext, useCallback, useContext, useEffect, useState, type KeyboardEvent } from "react"

@@ -1,4 +1,4 @@
import * as React from "react"
import { ComponentProps, ComponentType, createContext, CSSProperties, ReactNode, useContext, useId, useMemo } from "react"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { ComponentProps, ComponentType, createContext, CSSProperties, ReactNode, useContext, useId, useMemo } from "react"
import { type ComponentProps, type ComponentType, createContext, type CSSProperties, type ReactNode, useContext, useId, useMemo } from "react"

@@ -1,37 +1,37 @@
import * as React from "react"
import { ComponentProps } from "react"
import * as DialogPrimitive from "@radix-ui/react-dialog"
Copy link
Contributor

Choose a reason for hiding this comment

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

interesting, wonder if we should follow up by ctrl+Fing for import * as across the template

Comment on lines 2 to 3
import * as LabelPrimitive from "@radix-ui/react-label"
import { Slot } from "@radix-ui/react-slot"
Copy link
Contributor

Choose a reason for hiding this comment

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

even weirder, 2 different formats for different @radix packages

@@ -1,6 +1,6 @@
"use client"

import * as React from "react"
import { CSSProperties, ComponentProps, createContext, useCallback, useContext, useEffect, useMemo, useState } from "react"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { CSSProperties, ComponentProps, createContext, useCallback, useContext, useEffect, useMemo, useState } from "react"
import { type CSSProperties, type ComponentProps, createContext, useCallback, useContext, useEffect, useMemo, useState } from "react"

@@ -1,4 +1,5 @@
import { useTheme } from "next-themes"
import { CSSProperties } from "react"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
import { CSSProperties } from "react"
import type { CSSProperties } from "react"

@justinmcbride justinmcbride mentioned this pull request Jun 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants