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

186
Visualizações
Trying to rendering the options based on json data but getting map is not a function

I am trying to get a model based on the Brand. But getting the error when selection the next option

Error says bikeBrand is not a Function

Below is the Json data getting from backend

response from backend { BMW:["F900R", "F900XR"], KTM:["125 Duke", "250 Duke"]}

Then storing on the state using useState hook in React

const [bikeBrands, setBikeBrands] = useState("")

First option value is storing in below hook too

const [selectedBrand, setSelectedBrand] = useState("")

Problem is in the second selection option.

<select onChange={(e) => setSelectedBrand(e.target.value)}>
                        <option>Choose brand</option>
                        {Object.keys(bikeBrands).map((bikeBrand, index) => {
                            return <option>{bikeBrand}</option>
                        })}
                    </select>
                    <select onChange={(e) => setModel(e.target.value)}>
                        <option>Choose Model</option>
                        {Object.keys(bikeBrands).map((bikeBrand, index) => {
                            bikeBrand.map((brandModels, index) => {
                                return <option>{brandModels}</option>
                            })
                        })}

                    </select>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As you are doing

{Object.keys(bikeBrands).map((bikeBrand, index) => {
  bikeBrand.map((brandModels, index) => {
   return <option>{brandModels}</option>
  })
})}

note that Object.keys(bikeBrands) gives you array of keys, and these individual keys (one at a time) are stored in bikeBrand.

This bikeBrand is a variable which holds string BMW or KTM not the value.
So instead of writing bikeBrand.map
Use bikeBrands[bikeBrand].map to access Array values.

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