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

73
Visualizações
Update react select value on change

I am new to react and I am in a bit of a problem. To get the value of a particular react select dropdown I am using an onchange function. Here is the code for it.

const [selectedStatusCondition, setSelectedStatusCondition] =
    React.useState("");

const handleMaterialStatusChange = (value) => {
    setSelectedStatusCondition(value);
  };


                          <GridItem xs={2}>
                          <label>Material Status</label>
                          <ConditionDDL
                            id="materialstatusconditionDDL"
                            options={conditionDDLItems}
                            onChange={handleMaterialStatusChange}
                          />
                        </GridItem>

Howe ver I need the onChange function to set up another function after getting the value in the dropdown of the react select component which has values of E and A . On getting E run a set of functions and on Getting A run a set of functions.

Therefore I changed the code to put a wrapper function to do this like this:

                       <GridItem xs={2}>
                      <label>Material Status</label>
                      <ConditionDDL
                        id="materialstatusconditionDDL"
                        options={conditionDDLItems}
                        onChange={() => wrapperfunctionconfirm()}
                      />
                    </GridItem>

and wrapper function call the handle change function of the react select like this:

const wrapperfunctionconfirm = async (newToken = true) => {
    if (newToken) {
      const rsp = await getAuthorization();
    }
    var defaultOptions = {
      headers: {
        Authorization: "Bearer " + localStorage.getItem("tcm_accessToken"),
      },
    };
    setShrink(true);

    handleMaterialStatusChange(false);
    var status = selectedStatusCondition.value;
    

     console.log(
       "Status=" + status 
        
     );
  };

However I am getting status value as undefined. Clearly as set is an async method the value is yet not set. As I cannot use useEffect on change of a dropdown value to set the value immediately. What should I do How do I change the value of setting the handlechange function immideately?

Please help

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