Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

254
Visualizações
Is it bad practice to export all components into an index.js file?

I export all components to an index.js file. This means that I can import components into any other file by doing the bellow. This is simple and cleaner.

import { RocketCard, Container, Navbar, Button01 } from './Components/index';

This is what my index.js file looks like. Here I import and export all components.

import { RocketCard } from "./Cards/RocketCard"
import { SmallLabel } from "./SmallLabel"
import { StatusLabel } from "./StatusLabel"
import { Button01 } from "./Button01"
import { List } from "./hoc/List"
import { SearchBar } from "./SearchBar"
import { Container } from "./Layout/Container"
import { Navbar } from "./Layout/Navbar"

export { RocketCard }
export { SmallLabel }
export { StatusLabel }
export { Button01 }
export { List }
export { SearchBar }
export { Container }
export { Navbar }

Is this bad practice? Will it slow down my app in any way?

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It is difficult to say which is correct, it depends on the project and the arrangements in the team. I'm just saying what I would do and my opinion.

I think it's not right to specify everything in one file, because of this, structure is lost, in a large project this is important.

Yes, now you can import everything from one file, but creating a structure in the form of files and folders is a simple but important thing.

I'll give you an example. When I import BUTTON and see in the import path that it is from the shared folder, then I understand that this is a shared button that is used everywhere. But I can also import BUTTON from the HERO-BANNER folder and understand that this is a unique button for the HERO component. Something as simple as the import path makes life a little easier.

I am not suggesting that you abandon this idea, but I suggest changing it a bit.

I see you have a 'Cards' folder, great, create an index.js inside it and export components from the Cards folder that are needed elsewhere.

Same with the 'HOC' folder.

I see you have 4 components in the same file as the current Index.js file. I understand these are common components. I suggest creating a shared folder and putting them in there and creating an index.js file there with the export of these shared components.

Do the same with the 'layout' folder, create your own component export file there.

In general, the idea is good, but it needs a little detail.)

// Create index.js file inside Cards folder with this content.
export { RocketCard } from './RocketCard'

// Create index.js file inside HOC folder with this content.
export { List } from './List'

// Create shared folder and index.js with this content in shared folder
export { SearchBar } from './SearchBar'
export { SmallLabel } from './SmallLabel'
export { StatusLabel } from './StatusLabel'
export { Button01 } from './Button01'

// Create index.js file inside Layout folder with this content.
export { Container } from './Container'
export { Navbar } from './Navbar'
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda