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

210
Views
(React) Setting a default value for a dropdown list based on the global state

I have a landing page and a search page. The landing page has radio buttons that change the global state of boolean values. The idea is when I hit the search button on the landing, the app will take me to the search page with a dropdown list. I want the dropdown list's default value to be what was selected back on the landing page

  function getServiceDropdown(){
if (props.houseSitting) {
  return "isHome"
} else if (props.dropInVisits) {
  return "isVisit"
}

<select defaultValue={getServiceDropdown}>
  <option>Boarding</option>
  <option value="isHome">Home Sitting</option>
  <option value="isVisit">Drop-in Visits</option>
  <option>Day Care</option>
  <option>Dog Walking</option>
</select>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

State Block is heere for class componnent

    this.state = {
        bloodTypes: [
            { value: "Seçiniz", name: "Choose" },
            { value: "0 RH -", name: "0 RH -" },
            { value: "0 RH +", name: "0 RH +" },
            { value: "A RH -", name: "A RH -" },
            { value: "A RH +", name: "A RH +" },
            { value: "B RH -", name: "B RH -" },
            { value: "B RH +", name: "B RH +" },
            { value: "AB RH -", name: "AB RH -" },
            { value: "AB RH +", name: "AB RH +" },
        ],

On Change function is heere for class componnent

onChangeData = (type, event) => {

    const stateData = this.state;
    if (event === "" || event === "Choose")
        stateData[type] = undefined
    else
        stateData[type] = event

    this.setState({ stateData });
}

Select option component is heere for class componnent

   <select value={this.state.bloodType} onChange={e => 
         this.onChangeData("bloodType", e.target.value)}>
        {this.state.bloodTypes.map((type, index) =>
            <option 
                key={index} 
                value={type.value}>{type.name}</option>
        )
    } 
    </select>

....... ......

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!