I am implementing a component with <select>
and would like to use variants to toggle a switch.
I wonder which is the most practical way to do this.
Currently I have to convert text values into variants and viceversa.
type view = ConcreteView | DurockView | WoodView
@react.component
let make = () => {
let (view, setView) = React.useState(_ => WoodView)
<main>
<select
id="roof_material"
name="roof_material"
value={switch view {
| ConcreteView => "concrete"
| DurockView => "durock"
| WoodView => "wood"
}}
onChange={e => {
switch (e->ReactEvent.Form.target)["value"] {
| "concrete" => setView(_ => ConcreteView)
| "durock" => setView(_ => DurockView)
| "wood" => setView(_ => WoodView)
| _ => setView(_ => WoodView)
}
}} >
<option value="wood"> {`Madera`->React.string} </option>
<option value="concrete"> {`Concreto`->React.string} </option>
<option value="durock"> {`Durock`->React.string} </option>
</select>
<div className="mx-auto max-w-4xl">
{switch view {
| ConcreteView => <Concrete items />
| DurockView => <Durock items />
| WoodView => <Wood items />
}}
</div>
</main>
I wonder if RescriptReactRouter would help here, but I haven’t found any docs on it.
I also use select for product configurations, so it’s not limited to views.