Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free triallord kenu
204 PointsWHY NOT USE import React from 'react'?
if when we use import React from 'react' will get us everything, why don't we use that one instead. rather than importing every component one by one.
1 Answer
Rohald van Merode
Treehouse StaffHey lord kenu π
Importing the entire React library with ο»Ώimport React from 'react'
can be inefficient, especially in larger applications, as it increases the bundle size of your app unnecessarily. Instead, importing specific items you need from React allows your module bundler to include only the code you're using, resulting in a smaller bundle and faster load times.
As of React version 17, you don't need to import the whole ο»ΏReact object, so you typically only need to import only the hooks and other specific parts you're using. This makes your code more efficient and lean.
Hope this answers your question! π