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

234
Visualizações
How to show placeholder instead of the state's value at pageload?

I am trying to show the placeholder of an input instead of its state value. When I load the page it shows a blank select box, which makes sense because the testType state is null when the page first loads. How can I get it to just show the placeholder instead of the null state?

function RandomSelection(props) {
  const [testType, setTestType] = useState(null);
  const handleTestType = value => {
    setTestType(value);
  };

  return(
  <Select
    placeholder="Test Type..."
    value={testType}
    onChange={handleTestType}
  >
    <Option value="Option 1">
      Option 1
    </Option>
    <Option value="Option 2">Option 2</Option>
    <Option value="Option 3">Option 3</Option>
  </Select>

) }

The Select option is from Ant Design, however I feel the solution to this may apply to Material-UI and Bootstrap as well.

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

0

Since you never show the import path, and your code works perfectly fine using Antd's Select, my guess is that you're using the Select from MUI (partly because you also tagged material-ui in your question). So check your import path, because MUI Select placeholder is set by the label prop:

Right

import { Select } from 'antd';

Wrong

import { Select } from '@mui/material';
about 4 years ago · Juan Pablo Isaza Relatório

0

In const [testType, setTestType] = useState(null);, set useState's default value to what you want the placeholder to be instead of null.

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