Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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