Created
November 20, 2018 10:07
-
-
Save hamed-farag/7fae111f4139256f0498908000d8684f 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
import React from "react"; | |
export default class App extends React.Component { | |
state = {}; | |
onChange = event => { | |
this.setState({ [event.target.name]: event.target.value }); | |
}; | |
renderParent() { | |
const parents = [ | |
{ name: "parent1" }, | |
{ name: "parent2" }, | |
{ name: "parent3" } | |
]; | |
return parents.map((parent, index) => { | |
return ( | |
<input | |
type="text" | |
name={parent.name} | |
onChange={event => this.onChange(event)} | |
/> | |
); | |
}); | |
} | |
render() { | |
return ( | |
<React.Fragment> | |
{this.renderParent()} | |
<div> | |
<input | |
type="text" | |
value={this.state.input} | |
name="genericText" | |
onChange={event => this.onChange(event)} | |
/> | |
</div> | |
<div> | |
<span>{this.state.input}</span> | |
</div> | |
<input | |
type="button" | |
value="print" | |
onClick={() => { | |
console.info(this.state); | |
}} | |
/> | |
</React.Fragment> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment