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

222
Visualizações
How to get current value of the material UI component after rendering in react js

I have 2 components that I imported from material UI also I am using typescript. I have set the values from the database, I am trying to get those values that are set on the component by default without clicking on the component.

Basically, I am checking if the values are updated or not, if the values are previous values I will return nothing. My function is ready but I am not able to get the values when the page reloads, I am getting null.

My UI, the data is showing from the database: enter image description here

Select component:

const [status, setStatus] = useState<string | null>(null);

<FormControl sx={{ m: 1, minWidth: 120 }}>
        <InputLabel id="demo-controlled-open-select-label">Status</InputLabel>
        <Select
            labelId="demo-controlled-open-select-label"
            id="demo-controlled-open-select"
            open={open}
            onClose={handleClose}
            onOpen={handleOpen}
            value={details.status || status} // value from DB
            label="Status"
            onChange={(e) => setStatus(details.status || e.target.value)}
        >
            <MenuItem value={'Placed'}>
                <em>Placed</em>
            </MenuItem>
            <MenuItem value={'Packed'}>Packed</MenuItem>
            <MenuItem value={'Shipped'}>Shipped</MenuItem>
            <MenuItem value={'Delivered'}>Delivered</MenuItem>
            <MenuItem value={'Cancel'}>Cancel</MenuItem>
        </Select>
    </FormControl>

Date picker:

const [date, setDate] = useState<Date | null>(null);

<LocalizationProvider sx={{ width: 100 }} dateAdapter={AdapterDateFns}>
        <DatePicker
            label="Delivery Date"
            value={details.deliveryDate || date} //Value from DB
            minDate={new Date()}
            onChange={(newValue) => {
                setDate(newValue);
            }}
            renderInput={(params) => <TextField {...params} />}
        />
    </LocalizationProvider>

My function:

if (details.status !== status || details.deliveryDate !== date) {
        console.log('Do somthing')
    } else {
     console.log('None')
    }
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