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

275
Visualizações
Map database params field values to custom names

I am trying to handle an array of errors on the front end side and display them on the page. I am getting the fields that user has entered from the backend and trying to map them out. However, backend params are being returned in camelcase. Please see below:

enter image description here

I want to render: The input field(s) for email, favorite sport, gpa score are unacceptable

But I am seeing

The input field(s) for email, favoriteSport, gpaScore are unacceptable

Is there any way I can map the name of the params to a custom name?

Here is my code:

Array.isArray(errors) ? `The input fields for ${errors.map(item => item.param)} are unacceptable`

Any way i could map the param names to my own liking?

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

0

const mapper = (item) => {
  return {
   gpaScore: 'GPA Score',
   favoriteSport: 'Favorite Sport',
  }[item.param] || 'Unknown property'
} 

return `The input fields for ${errors.map(item => mapper(item)).join(', ')} are unacceptable`
about 4 years ago · Juan Pablo Isaza Relatório

0

This is where you could use something like react-intl to format messages but in general, you'd need something that turns programmatic keys into user-friendly messages

const t = {
  email: "email",
  favoriteSport: "favourite sport",
  gpaScore: "GPA score"
}

const fields = errors.map(({ param }) => t[param] ?? param)

const message = `The input fields for ${fields.join(", ")} are unacceptable`
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