#import React from 'react' when using hooks or just { useState }

18 messages · Page 1 of 1 (latest)

mortal thornBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

dusk flower
#

That's the kind of stuff you'd want to test because it can change over time/there might be bugs/edge cases/specificities depending on your package

#

you can output a bundle analysis

#

the recent change (can tell the exact version) is that now Next.js automatically handles libs with "barrel" files, namely lodash, out of the box

hasty shuttle
#

btw - this came along with React 17 jsx transforms. You don't need to import react from 'react' with next

I also use the "Import Cost" extension - some libraries may not be configured correctly for treeshaking

oak fossil
#

i assume not

#

still a cool extension tho

dusk flower
#

anyway last time I've checked I could see page specific code, layout specific code, dynamic JS chunks etc.

#

but I didn't use it recently, I need to check again

candid mauve
#

i never checked this in more details so this most likely is wrong, but somehow i feel like import React from "react", import { useState } from "react" and import * as React from "react" all have the same impact on bundle size

#

not based on any technical reasons but simply because, if one way is better than the others, why are all of them still used by many people

#

it's been quite a while since import React from "react" is no longer required

hasty shuttle
#

so, functionally the same