Answer the question
In order to leave comments, you need to log in
How to write a handler?
class FormContainer extends Component {
constructor() {
super()
this.state = {
seo_title: ''
}
this.handleChange = this.handleChange.bind(this)
}
handleChange(event) {
this.setState({ [event.target.id]: event.target.value })
}
render() {
const { seo_title } = this.state
return (
<form id="article-form">
<Input
text="SEO title"
label="seo_title"
type="text"
id="seo_title"
value={seo_title}
handleChange={this.handleChange}
/>
</form>
)
}
}
class FormContainer extends Component {
state = {
seo_title: ''
}
handleChange = event => {
this.setState({ [event.target.id]: event.target.value })
}
render() {
const { seo_title } = this.state
return (
<form id="article-form">
<Input
text="SEO title"
label="seo_title"
type="text"
id="seo_title"
value={seo_title}
handleChange={this.handleChange}
/>
</form>
)
}
}
Answer the question
In order to leave comments, you need to log in
The second option is the unspoken standard in the React community. This uses the experimental babel-plugin-transform-class-properties syntax .
The first option is preferable when you need to make the component inherit, since the functions of the class property are not inherited.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question