I'm using this function to remove an item from my state array in React
removeProduct(index) {
this.setState(prevState => ({
selectedProducts: update(prevState.selectedProducts, {$splice: [[index, 1]]}),
}))
}
it is being passed through like this:
<Basket items={this.state.selectedProducts} removeItem={this.removeProduct.bind(this)}/>
<BasketItem product={product} key={index} remove={this.props.removeItem}/>
and then called like this:
<button onClick={props.remove.bind(this)}>x</button>
but its not removing that specific item. Its only removing the first item in the array.
Can anyone help?
BasketItem- where's that coming from inBasket?BasketItemcomponent has a prop calledindex- where is that passed to it from? Is it inside theBasketcomponent?