Skip to content

Instantly share code, notes, and snippets.

@danielearwicker
Created July 8, 2017 08:22
Show Gist options
  • Save danielearwicker/44aa07c670924ede981b330b86b5e81b to your computer and use it in GitHub Desktop.
Save danielearwicker/44aa07c670924ede981b330b86b5e81b to your computer and use it in GitHub Desktop.
Very minimal two-way binding example
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