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

192
Visualizações
Why this setState is like this and how this is working?

Sorry I don't know how to search this kinda problem and I didn't find any answer to this but I'm so confused with this code, its a setState function for an OTP verification :

setCode((currCode) =>
  currCode
  .split('')
  .map((ch, i) => (i !== idx ? ch : isCharNumber ? val : isEmpty ? '_' : ch))
  .join(''),
);

I understand the map part I'm just wondering about that comma "," after the join function. why? if I delete that the code works but ESlint tell me to put that at the end. does it return an object? it just goes through the state which is "____" (four underscores) and change each _ to digit. I really appreciate if someone explain this to me and tell me how can I search and look for this kind of confusions. ty

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

0

does it return an object?

No.

I'm just wondering about that comma "," after the join function. why?

In modern JavaScript, it's optional to have a comma after the last argument in a function call (and after the last parameter in a function parameter list), like this:

example(
    firstArg,
    secondArg,
    thirdarg,
  //        ^−−−−−−−−−−−− optional
)

It makes it convenient when adding/removing arguments later not to have to worry about adding/removing a comma.

That's what's going on in your code, there's a single argument to setCode (the arrow function), followed by a comma.

if I delete that the code works but ESlint tell me to put that at the end.

ESLint can be configured to require trailing commas in function argument lists; apparently it's configured that way in your setup. If you don't like the rule, you can turn it off (in private projects) or discuss it with your team (in team projects).

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