Replace import * as React from "react" with named imports for better tree-shaking #7893
kouzoukian
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Most components in the ShadCN UI library use:
While this guarantees compatibility with the JSX runtime and some SSR setups, itrevents optimal tree-shaking. This pattern can unnecessarily bloat the final bundle inpplications that only use a subset of React APIs.
Why it matters
* as React
pulls the full React namespace into scope, even if onlyuseEffect
or useId` is used.React
object."jsx": "react-jsx"
enabled, here's no need to importReact
at all just to use JSX.Proposed change
Replace:
With:
And remove the
React.
prefix where appropriate. This aligns with modern best ractices and improves performance without sacrificing compatibility.Potential caveats
Beta Was this translation helpful? Give feedback.
All reactions