In this class:
export class Usuario extends React.Component{
constructor(props){
super(props)
this.state = {
usuario: ""
}
}
onChange(e){
this.setState({
usuario: e.target.value
})
}
onSubmit(e){
e.preventDefault()
this.props.onSubmit(this.state.usuario)
}
render(){
return <div>
<form onSubmit = {this.onSubmit}>
<input type="text" placeholder="Ingresa tu nombre de usuario" onChange={this.onChange} />
<input type="submit" />
</form>
</div>
}
}
I understand clearly what this method does:
onChange(e){
this.setState({
usuario: e.target.value
})
}
Once the input starts changing the this.state.usuario changes to whatever the user is typing on input.
BUt, what about this one:
onSubmit(e){
e.preventDefault()
this.props.onSubmit(this.state.usuario)
}
I get this method will trigger when the user clicks the “submit button”, but apparently this doesn´t change anything on the state.
Apparently the second line of this function is somekind of function but this.props.onSubmit can´t be a function.
I don´t get what really this is doing? What this line means??
this.props.onSubmit(this.state.usuario)