react-link-state-vm
Link state with virtual method.
To use the experimental function bind operator ::
, you need @babel/plugin-proposal-function-bind (or @babel/preset-stage-0). Or you can use Function.prototype.call
to assign correct this
value. Example:
// Proposal 👍this::; // StandardvalueLink;
Example Input
; { // this.state.name -> undefined | "some text" return <input type="text" ...this:: />; }
Checkbox and Radio
; { // this.state.race -> undefined | true | false return <input type="checkbox" ...this:: />; } { // this.state.category -> undefined | [] | ["motogp", "moto3", ...] return <div> <input type="checkbox" ...this:: /> <input type="checkbox" ...this:: /> <input type="checkbox" ...this:: /> </div> ; } { // this.state.category -> undefined | "motogp" | ... return <div> <input type="radio" ...this:: /> <input type="radio" ...this:: /> <input type="radio" ...this:: /> </div> ; }
Select
; { // this.state.bike -> undefined | "ducati" | ... return <select ...this::> <option value="ducati">Ducati</option> <option value="honda">Honda</option> <option value="suzuki">Suzuki</option> <option value="yamaha">Yamaha</option> </select> ; } { // this.state.bikes -> undefined | [] | ["ducati", "honda", ...] return <select ...this::> <option value="ducati">Ducati</option> <option value="honda">Honda</option> <option value="suzuki">Suzuki</option> <option value="yamaha">Yamaha</option> </select> ; }
About the Implementation
In a simple form, valueLink
could be just a function that returns value
and onChange
handler.
{ return value: thisstatename this ;}