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

109
Visualizações
React generating UI from object - console.log works but nothing generated

I have code that generates my react UI, and it works with a list of languages to generate checkboxes for language selection. For example when in state

languages = {English: true, French: false} 

however when i change it to an object which contains the values from the DB, I get no error, but nothing loads.

[
{
    "language_name": "English",
    "lang_num": 1,
    "checked": false
},
{
    "language_name": "Mandarin Chinese",
    "lang_num": 2,
    "checked": false
},
]

The code is:

       {   
        Object.entries(this.props.languages).forEach(([key, value]) => {
          console.log(this.props.languages[key].language_name),
          <label id="checkbox-margin">
            <input
              type="checkbox"
              value={this.props.languages[key].language_name}  
              checked={this.props.languages[key].checked}
              onChange={this.handleLangClick}
            /> {this.props.languages[key].language_name}
          </label>
      }
      )

The console.log lists each language string fine, i get them all printed in the console, but nothing is generated on the UI. Any idea why?

Thanks!

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

0

Try to use the map function to iterate through the array:

{this.props.languages ? this.props.languages.map(language => {
    return (
        <label id="checkbox-margin" key={language.lang_num}>
            <input
                type="checkbox"
                value={language.language_name}  
                checked={language.checked}
                onChange={this.handleLangClick}
            /> {language.language_name}
        </label>
    )}) : 'Loading languages...'
}
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