Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@llopez
Created August 18, 2016 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save llopez/ee1023672f4f219fa8b37b24a8ec6067 to your computer and use it in GitHub Desktop.
Save llopez/ee1023672f4f219fa8b37b24a8ec6067 to your computer and use it in GitHub Desktop.
class Form extends React.Component {
_fill(e) {
console.log(e.target.value);
}
render() {
return(
<form>
{this.props.children}
</form>
);
}
}
class Field extends React.Component {
_setValue(e) {
this.props.fill(e);
}
render() {
return (
<input type="text" onChange={this._setValue}/>
);
}
}
render(
<Form>
<Field name="first_name" />
<Field name="last_name" />
</Form>,
document.getElementById('form1')
);
render(
<Form>
<Field name="first_name" />
<Field name="last_name" />
<Field name="age" />
</Form>,
document.getElementById('form2')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment