I tried out this code. Everything seems fine to me but compiler say's onDismiss is undefined? Please help me out on this one....
import React, { Component } from 'react';
const list=[{title:'React',id:0},{title:'Redux',id:1}];
class App extends Component {
constructor(props) {
super(props);
this.state={list,};
this.onDismiss=this.onDismiss.bind(this); }
onDismiss(id){
const isnotid=item=>item.id!==id;
const uplist=this.state.list.filter(isnotid);
this.setState({list : uplist});
}
render() {
return( <div className="App">
{this.state.list.map(item=>
<div key={item.id}>
<span>
{item.title}
</span>
<button onClick={()=>onDismiss(item.id)} type="button">
Dismiss
</button>
</div>)}</div>);
}
}
export default App;
It is a simple app that displays a list. A dismiss button is used to remove any unneeded content. Basically, I am just practicing Reactjs but don't have the clue about why my Ondismiss( The function to change content by updating component state) function is Undefined as described by compiler. Fixed typo's and little mistakes but it onDismiss function still remains undefined!
onDimissin the example code.