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

321
Views
How to show one values in select options while passing to state other?

So I need to show "Yes" or "No" in the dropdown, but to pass "admin" or "member" to api. Right now I'm doing it via ternary operator, checking either e.target.value or I also checked state "role" when passing it to api request, and it worked. But is there any other, nicer and more reliable way?

 export function EditableRole({
      employee,
      onSave,
      onCancel,
    }: EditableRoleProps) {

  const [role, setRole] = useState("MEMBER");

  const handleSave = () => api.updateUser(role)


  return (
    <div className={styles.wrapperEditable}>
      <Dropdown
        className={styles.dropdownRole}
        options={["Yes", "No"]}
        value={role}
        onChange={(e) =>
          setRole(e.target.value === "Yes" ? Role.ADMIN : Role.MEMBER)
        }
      />
      <Icon name="tick" onClick={() => handleSave()} />
      <Icon name="cancel" onClick={onCancel} />
    </div>
  );
}

Below is my Dropdown component:

export interface DropdownProps {
  label?: string;
  id?: string;
  options: string[];
  value: string;
  onChange: (e: ChangeEvent<HTMLSelectElement>) => void;
  className?: any;
}

export function Dropdown({
  label,
  id,
  options,
  onChange,
  className,
}: DropdownProps) {
  return (
    <div className={styles.wrapper}>
      <label className={styles.labeltext} htmlFor={id}>
        {label}
      </label>
      <select
        id={id}
        className={cx(className, styles.dropdown)}
        onChange={onChange}
      >
        {options.map((option) => (
          <option key={option}>{option}</option>
        ))}
      </select>
    </div>
  );
}
about 4 years ago · Santiago Gelvez
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!