Skip to content

Instantly share code, notes, and snippets.

@clc80

clc80/App.js

Created Jun 4, 2018
Embed
What would you like to do?
Changing the state with new value
import React, { Component } from 'react';
import Form from './components/Form'
import './App.css';
class App extends Component {
constructor(props) {
super(props);
this.state = {
formItems: ['one', 'two', 'three'],
newFormElement: ''
}
}
handleSubmit(e) {
e.preventDefault();
}
handleChange(e) {
this.setState({newFormElement: e.target.value})
}
render() {
return (
<div className="App">
<ul>
{this.state.formItems.map( (element, index) =>
<Form
key={index}
formElement={element}
/>
)}
</ul>
<form onSubmit={(e) => this.handleSubmit(e)}>
<input type="text"
value={this.state.newFormElement}
onChange={ (e) => this.handleChange(e)}
/>
<input type="submit" />
</form>
</div>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.