no arquivo do formulario, a gente cria o constructor com o this.title e this.text,
porque precisamos desse constructor??
import React, { Component } from 'react'; import './style.css'
class Form extends Component {
// constructor() {
// super();
// this.title = '';
// this.text = '';
// }
handleChangeTitle(event) {
event.stopPropagation();
this.title = event.target.value;
console.log(this.title);
}
handleChangeText(event) {
event.stopPropagation();
this.text = event.target.value;
console.log(this.text);
}
createCard(event) {
event.preventDefault();
event.stopPropagation();
console.log(`Um novo card foi criado ${this.title} ${this.text}`);
}
render() {
return (
<section className="formSection">
<form
className="form"
onSubmit={this.createCard.bind(this)} >
<input
className="input"
type="text"
placeholder="title"
onChange={this.handleChangeTitle.bind(this)}/>
<textarea
className="textarea"
placeholder='Write your notes'
onChange={this.handleChangeText.bind(this)}/>
<button className="btn btn-primary">Create</button>
</form>
</section>
)
}
}
export default Form;
eu comentei essas linhas do arquivo e ele respondeu igual, porque usamos ele nesse caso??