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

220
Visualizações
Why is ( ) used instead of curly braces / brackets { } inside Javascript Map function?

Inside map function why is the function defined with ( ) => ( ) instead of ( ) => { }

  {mylist.map((elem, index) => (
            <div key={elem.id}>
              <h2>{elem.title}</h2>
            </div>
          ))}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can leave () out if you put everything in one line:

 {mylist.map((elem, index) => <div key={elem.id}><h2>{elem.title}</h2></div>)}

If you want to return something, but it take several lines, then you have to use ():

{mylist.map((elem, index) => (
    <div key={elem.id}>
        <h2>{elem.title}</h2>
    </div>
))}

Finally, when you want to perform something and THEN return the result, you need to use {}. You still need to care when you return something - if it takes several lines, you have to wrap it with():

{mylist.map((elem, index) => {
    const id = elem.id;
    const title = elem.title;
    return (
        <div key={id}>
            <h2>{title}</h2>
        </div>
    );
})}

For returning objects it's also a bit different: You can wrap your object into brackets: ({...}) or explicitly return it: () => { return { ... }}

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