Skip to content

Instantly share code, notes, and snippets.

@hamed-farag
Created November 20, 2018 10:07
Show Gist options
  • Save hamed-farag/7fae111f4139256f0498908000d8684f to your computer and use it in GitHub Desktop.
Save hamed-farag/7fae111f4139256f0498908000d8684f to your computer and use it in GitHub Desktop.
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