I have in my state:
this.state = { inputs: ['0'] }
In my render :
{this.state.inputs.map((input, i) => <Travel formName={FORM_NAME} number={input}/>)}
<button onClick={ () => this.appendInput() }> CLICK ME TO ADD AN INPUT </button>
<button onClick={ () => this.deleteInput() }> Delete </button>
Now when I click on this.appendInput()
I add a field like this:
appendInput() {
var newInput = `${this.state.inputs.length}`;
console.log("`${this.state.inputs.length}`" , `${this.state.inputs.length}`)
this.setState(prevState => ({ inputs: prevState.inputs.concat([newInput]) }));
console.log("this.state.inputs add ", this.state.inputs)
this.forceUpdate();
}
But I don't understand how can I do with the deleteInput
, how can I delete the last field in this way?
EDIT: I have tried like this:
deleteInput(){
var newInput = this.state.inputs.pop();
this.setState( ({ inputs: newInput }));
this.forceUpdate();
}
but then I receive the message:
_this.state.inputs.map