I am trying to display my todolist based on the filter the user chooses. at the moment, I have written the code for showing completed only. but it's not working.
Please take a look and tell why it's not working
import React,{Component} from 'react';
import './reminderListStyles.css';
import Filters from './Filters';
class ReminderList extends Component{
constructor(){
super();
this.state={
filter:"completed"
}
this.getFilter=this.getFilter.bind(this);
}
getFilter(x){
this.setState({
filter:x
});
//alert(x);
}
render(){
return(
<div>
<ul>
{this.props.reminder.map((item)=>{
if(this.state.filter==='show_completed'){
if( item.completed){
return <li key={item.id}
style={{textDecoration: item.completed? 'line-through':'none'}}
onClick = {()=>{this.props.onToggle(item.id)}} >
< input type="checkbox" checked={item.completed} />{item.text}</li>
}
}
return <li key={item.id}
style={{textDecoration: item.completed? 'line-through':'none'}}
onClick = {()=>{this.props.onToggle(item.id)}} >
< input type="checkbox" checked={item.completed} />{item.text}</li>
})}
</ul>
<Filters reminders={this.props.reminder}
filterState={this.getFilter}
/>
</div>
)
}
}
export default ReminderList;