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

518
Visualizações
mui TextField in React loosing focus every typing one character after put key props in <div> parent

I have a dynamic component with TextField, but when i put key props in div parent, the TextField always lose focus after typing 1 character, if i delete key props, all normaly. Here my component code.

<div key={uuid()} style={{ display: 'flex', alignItems: 'center', marginBottom: Dimens.px10 }}>
            <TextField
                style={{ marginRight: Dimens.px20 }}
                fullWidth
                required={props.required}
                id="outlined-textarea"
                defaultValue={props.data}
                autoComplete='off'
                label={props.label}
                placeholder={props.label}
                onChange={props.onChange}
            />
            <div style={{
                width: 50,
                maxWidth: 40
            }}>
                <CButton outline isDriver label={<p style={{ fontWeight: 'bold', margin: 0, padding: 0 }}>-</p>} onClick={props.onDeleteClick} />
            </div>
        </div>

How could this happen?

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

0

Keys must be stable, <div key={uuid()}> assigns new key.

If they're not stable then React cannot understand that this might be the same as before and then just re-renders. That is the reason if you remove the the key then all works well.

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