Last active
September 27, 2016 21:57
-
-
Save mlapshin/538a3d0a071f2d73dc95673b4696f7b9 to your computer and use it in GitHub Desktop.
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
const Input = props => { | |
return <input {...props} />; | |
} | |
const FormRow = props => { | |
return <div className="formRow">{props.children}</div>; | |
} | |
const makeBindFn = (formId, formComp) => { | |
return inputName => { | |
return { | |
onChange: (e) => { formComp.handleInputChange(inputName, e.target.value) }, | |
defaultValue: formComp.state[inputName] | |
}; | |
}; | |
} | |
class Form extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
email: "[email protected]" | |
}; | |
} | |
handleInputChange(inputName, newVal) { | |
this.setState({ [inputName]: newVal }); | |
} | |
render() { | |
const bind = makeBindFn("login-form", this); | |
return ( | |
<FormRow> | |
<Input {...bind("email")} someProp="someVal" /> | |
<Input {...bind("password")} someProp="anotherVal" /> | |
<pre>Form model: {JSON.stringify(this.state)}</pre> | |
</FormRow> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment