Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!