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

95
Visualizações
Passing BEM className in React

In the example below, how can I use the Post component in such a way that new posts and old posts have their own unique classes that follow BEM recommendations.

  1. Every element needs it's own unique className
  2. Cascading dependencies (.posts-new post or .posts-old post) should be avoided
  3. Each component defines a new Block on its outermost element

What I want is for the className to reflect new vs. old. Ideally, post-new and post-old.

One approach I've considered is to pass "new" or "old" via a props attribute (type="old", for example) to the Post component and then dynamically create the className (this post leverages such an approach). Is that the recommended approach for such a situation or is there another technique I'm not seeing?

// Display new posts
Posts className="posts-new"
  Post className="?"

// Display old posts
Posts className="posts-old"
  Post className="?"
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

In the end, I chose to use an attribute to pass "new" and "old" from the Posts component to the Post component.

<Posts type="new" />
<Posts type="old" />

Then, in the Post component I was able to add this to the className of my article tag via a template literal.

<article className={`post post-${props.type}`}>

From the feedback I've received from other devs, this is an acceptable approach.

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