Created
July 8, 2017 08:22
-
-
Save danielearwicker/44aa07c670924ede981b330b86b5e81b to your computer and use it in GitHub Desktop.
Very minimal two-way binding example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
function twoWay(Comp) { | |
return props => { | |
const { value, children, ...others } = props; | |
return ( | |
<Comp {...others} | |
value={value.get()} | |
onChange={ev => value.set(ev.target.value)}> | |
{children} | |
</Comp> | |
); | |
} | |
} | |
export const Input = twoWay(p => <input {...p}/>); | |
export const Select = twoWay(p => <select {...p}/>); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment