scrimba
Learn React for free
React Form Part 2
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

React Form Part 2
AboutCommentsNotes
React Form Part 2
Expand for more info
App.js
run
preview
console
import React, {Component} from "react"

class App extends Component {
constructor() {
super()
this.state = {
firstName: "",
lastName: ""
}
this.handleChange = this.handleChange.bind(this)
}

handleChange(event) {
const {name, value} = event.target
this.setState({
[name]: value
})
}

render() {
return (
<form>
<input
type="text"
value={this.state.firstName}
name="firstName"
placeholder="First Name"
onChange={this.handleChange}
/>
<br />
<input
type="text"
value={this.state.lastName}
name="lastName"
placeholder="Last Name"
onChange={this.handleChange}
/>

{
/**
* Other useful form elements:
*
* <textarea /> element
* <input type="checkbox" />
* <input type="radio" />
* <select> and <option> elements
*/
}








<h1>{this.state.firstName} {this.state.lastName}</h1>
</form>
)
}
}

export default App
Console
index.html
-15:21