Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

319
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda