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

178
Visualizações
Select input is not showing value when using map function

Im trying material ui select but it is not working as i would like to. it is not showing the default value when i use the map function but it does when using the traditional way.

*** The way which is working ***

<Select
              id="standard-select-categories"
              defaultValue="UK"
              label="Select Country"
              name="country"
              select
              variant="standard"
            >
             <MenuItem value="USA">
                USA
              </MenuItem>
              <MenuItem value="UK">
               UK
              </MenuItem>
              <MenuItem value="Japon">
               Japon
              </MenuItem>

            </Select>

input shows UK as the selected country by default

*** The way which is NOT working ***

<Select
              id="standard-select-categories"
              defaultValue="UK"
              label="Select Country"
              name="country"
              select
              variant="standard"
            >

              {Countries_Flags.map((option) => (
                <MenuItem 
                key={option.name}
                value={option.name}
                >
                  {<img src={option.flag} alt={option.name} className="select-country-items" />}
                  {option.name}

                </MenuItem>
              ))}
            </Select>

input doesnt show UK as the selected country by default

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

The value being assigned to the MenuItem needs to match the value you set for the defaultValue prop on the select.

eg: [{name:"United Kingdom"}] . "United Kingdom" should be the defaultValue

        <Select
          id="standard-select-categories"
          defaultValue="United Kingdom"
          label="Select Country"
          name="country"
          select
          variant="standard"
        >
          // "United Kindom" for the defaultValue prop
          <MenuItem value={"United Kindom"}>UK</MenuItem>
          // "United States of America" for the defaultValue prop
          <MenuItem value={"United States of America"}>USA</MenuItem>
        </Select>
about 4 years ago · Santiago Gelvez 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