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

122
Visualizações
How to keep the selected item from select in a react application to be same on reloading the page?

How to keep the selected item from select in a react application to be same on reloading the page?
I have to maintain the state as per the last selection by the user on reloading. please help me edit this code so that it works properly on reloading the page with same state.

function handleChangeBranch(value: any) {
        AdvertiseService.fetchNewStore(
          `${value}`,
          (store: any) => {
            // brand = store;
            setSelectedBranch(store);
          },
          () => { },
          () => { }
        );
        setBranchChanged(true)
    
      }
    
    
    
    
    
    
    <Button className="city-selection-btn">
                    <Select
                      defaultValue={branches?.branches?.length === "1" ? selectedBranch?.name : "choose location"}
                      style={{ width: 120, border: "none" }}
                      onChange={handleChangeBranch}
                    >
                      {branches &&
                        branches.branches?.map((branch: any) => (
                          <Option
                            value={branch.id}
                            className="advertise-branch-list-item"
                            key={branch.id}
                          >
                            {branch.name}
                          </Option>
                        ))}
                    </Select>
                  </Button>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can store the selected value on localStorage or URL, then in componentDidMount you can get the value you stored (on localStorage or URL) and set to the state that you bind to the Select component value.

P.S. you can try localStorage without installing any library:

localStorage.getItem("branch") to get data
localStorage.setItem("branch", value) to set data

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