Typescript import best practices?

Is there a difference in the compiled package between import { useEffect } from "react" vs
import * from "react"
React.useEffect(() =>{})
import * from "react"
React.useEffect(() =>{})
? I remember someone showing how import Box from "@mui/material/Box"; was significantly different than import Box from "@mui/material"; and wasn't sure if this was similar.
6 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
CuriouslyCory
CuriouslyCoryOP3y ago
I just ran a quick test with create-react-app (react 18) and confirmed that the difference in compiled package between useEffect vs React.useEffect has zero impact on the resulting package.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
CuriouslyCory
CuriouslyCoryOP3y ago
Thanks. I haven't used one of those before, I'll dig into it. Interestingly the difference between import Box from '@mui/material/Box and import {Box} from '@mui/material is also 0 with latest versions.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Develliot
Develliot3y ago
Named imports are better than default imports because if it can be tree shaken it will be, default can never be. It took me ages to figure out how to make a treeshakable lib, the only tool at the time that seemed to work was roll up, webpack could treeshake a build but at the time couldn't make something that was treeshakable. There is a subtle difference between tree shaking and a bundler that omits unused code.
Want results from more Discord servers?
Add your server