Answer the question
In order to leave comments, you need to log in
How to add multiple elements to an array under the same id?
For example: given a form with "input' and "textarea", how can I put their values in an array under the same id? And is it possible to use "input" as id?
addItem = (e) => {
e.preventDefault();
const{ inputText, textareaText } = this.state;
this.setState({
items: [],
inputText: '',
textareaText: '',
})
this.state.items.push( inputText, textareaText );
this.setState ({ items: this.state.items });
}
render(){
const { inputText, textareaText } = this.state;
const list = this.state.items.map(({ id, value, title }) => {
return <li key={id} value={ value }>{ title }</li>;
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question