I am trying to display data from another file into a Table component in React. The data is getting displayed but the delete method isn't working. I am not sure what mistake I have done over here. I am not getting any console errors and the delete button does say it's clicked in the console.
Movie.js
import React, { Component } from 'react'
import { Table } from 'react-bootstrap';
import Data from './data';
export default class Movie extends Component {
constructor(){
super();
this.state={
movies:Data
}
console.log(this.state.movies)
this.handleDelete=this.handleDelete.bind(this);
}
handleDelete= movie=>{
const del=this.state.movies.filter(item => item !== movie.id);
this.setState({
movie:del
})
console.log("clicked")
}
render() {
//const store=this.state.movies.id;
const show= this.state.movies.map((movie,i)=>{
return(
<tr key={i}>
<td>{movie.id}</td>
<td>{movie.name}</td>
<td>{movie.price}</td>
<td>{movie.rating}</td>
<td> <button onClick={()=>this.handleDelete(movie)}>Delete</button></td>
</tr>
)})
return (
<div>
<Table striped bordered hover>
<thead>
<tr>
<th>#</th>
<th>Movie</th>
<th>Price</th>
<th>Rating</th>
</tr>
</thead>
<tbody>
{show}
</tbody>
</Table>
</div>
)
}
}
Data.js
const i=[
{
id:1,
name:"Captain america",
price:"$10",
rating:'5 stars'
},
{
id:2,
name:"Batman",
price:"$12",
rating:'4 stars'
},
{
id:3,
name:"Arrow",
price:"$8",
rating:'3 stars'
}
]
const data=i;
export default data;
keyLists and Keys