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
DatePicker throws Uncaught TypeError of undefined in onChange

I have a DatePicker which is throwing the following error message: Uncaught TypeError: Cannot read properties of undefined (reading 'value').

My data is being pulled from an API where some items date field is null. Initial render of the page is fine, where the TextFields and 2 empty date pickers display, but when I input a date, the error is thrown.

When an item does have a date value, it is returned from the API like this Aug 12 2020 12:00AM

I want to disregard the time and append the date to the date picker when the there is a date present. If there is no date, I want to append todays date.

The following code will display a TextField or a DatePicker based on the value of FieldType.

Here is my API request:

const [details, setDetails] = useState("");

const fetchDetails = async () => {
        setBusy(true);
        setDetails(await fetch(`/fiscalyears/FY2023/intakes/${params.id}/details`).then((response) => response.json()));
        setBusy(false);
};

This is how I switch between TextFields, Selects and the DatePicker:

return (
<Box>
    {details["fields"]?.map((row, index) => {
    if (row?.FieldType === "Text" || row?.FieldType === "Decimal" || row?.FieldType === "Number") {
        return (
            <TextField
                value={row?.Value || ""}
                onChange={(e) => {       
                    setDetails((prev) => {
                        const update = [...prev.fields];
                        update[index] = {
                            ...update[index],                
                            Value: e.target.value,
                        };
                        return { ...prev, fields: update };            
                    });
                }}
            />
        );
    }
    if (row?.FieldType === "Date") {        
        return (
            <LocalizationProvider dateAdapter={AdapterDateFns}>
                <DatePicker
                    label={row?.FieldName || ""}
                    renderInput={(params) => <TextField {...params} />}
                    value={row?.Value || ""}
                    onChange={(e) => {
                        setDetails((prev) => {
                            const update = [...prev.fields];
                            update[index] = {
                                ...update[index],
                                Value: e.target.value,
                            };
                            return { ...prev, fields: update };
                        });
                    }}
                />
            </LocalizationProvider>
        );
    } 
    })}
</Box>
)
about 4 years ago · Juan Pablo Isaza
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