im making a to-do list using react but I'am not able to understand the error can please some one tell me what I'am doing wrong.
constructor(props) {
super(props);
this.state = {
userInput: '',
list:[]
}
}
changeUserInput = (Input) => {
this.setState({userInput: Input});
}
onButtonSubmit = (Input) => {
let listArray = this.state.list;
listArray.push(Input);
this.setState({list: listArray})
}
render() {
return (
<div className="App">
<Input
changeUserInput = {this.changeUserInput}
onButtonSubmit = {this.onButtonSubmit}
/>
<ul>
{this.state.list.map((val) => <li>{val}</li>)}
</ul>
</div>
input.js
import React from 'react';
const Input = ({changeUserInput, onButtonSubmit}) => {
return(
<div>
<p className = 'f2'>
{'Make a shopping list by adding items'}
</p>
<div>
<input className = 'w-70 ma2 pa2 br-pill' type = "text"
placeholder = "enter items" onChange={changeUserInput} />
<div>
<button className= 'f6 grow br-pill ba bw1 ph3 pv2 mb2 dib black
pointer' onClick ={onButtonSubmit} >Add Item</button>
</div>
</div>
</div>
);
}
export default Input;
Warning: Each child in a list should have a unique "key" prop. Warning: This synthetic event is reused for performance reasons Uncaught Invariant Violation: Objects are not valid as a React child