joaopaulomoraes / reactjs-vite-tailwindcss-boilerplate

This is a boilerplate build with Vite, React 18, TypeScript, Vitest, Testing Library, TailwindCSS 3, Eslint and Prettier.
https://reactjs-vite-tailwindcss-boilerplate.vercel.app
MIT License
575 stars 106 forks source link

Resolved default import #37

Closed JDaniielC closed 2 years ago

JDaniielC commented 2 years ago

Problem: Remove default of export in app.tsx for follow the pattern of importation, and import named import { App } from Explaining: When exporting by default can't change the name's component in importation, then, if change the name in component should be changed in importation too, however, if export without default, you can change the name of importation component facilitating a refactoring of code.

vercel[bot] commented 2 years ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
reactjs-vite-tailwindcss-boilerplate ✅ Ready (Inspect) Visit Preview May 29, 2022 at 10:30PM (UTC)
joaopaulomoraes commented 2 years ago

Hi, @JDaniielC! Thanks for the contribution.

In this case, I don't think we have any kind of problem, it would just be a preference you would have with your project after clone and start to code. 😉

In general, it is always a good idea to have default exports, precisely to not create many other components within the same file, making it difficult to compose and possibly test it.

Anyway, here are some examples you could do in this case.

With default export:

import Foo from 'components/App' import Foo from 'components/Foo' <Foo />

Without default export:

import { App } from 'components/App' <App />

import { App as Foo } from 'components/App' <Foo />

Again, I really appreciate your cooperation and time and I'm available to help you with any other questions. ❤️