Skip to main content

4.1 Create Input Field

import React, { Component } from "react";
import "./App.css";

class App extends Component {
state = {
userInput: "",
};
inputChangeHandler = (event) => {
this.setState({
userInput: event.target.value,
});
};
render() {
return (
<div className="App">
<input
type="text"
value={this.state.userInput}
onChange={(event) => this.inputChangeHandler(event)}
/>
<p>{this.state.userInput.length}</p>
</div>
);
}
}

export default App;