I was following this example of filtering data link. But i Have problem with includes function.
const updateArticles = (e) => {
if(e.target.name){
if(e.target.checked){
const currState = [...this.state.defaultData];
const newState = currState.filter(article => article.tags_array.includes(e.target.name));
this.setState(prevState =>({
articles: prevState.selectedArticles.length >= 1 && prevState.articles.length <=
prevState.defaultData.length ? [...newState, ...prevState.selectedArticles] : newState,
selectedArticles: [...newState, ...prevState.selectedArticles]
}));
} else {
if (this.state.articles.length === 1){
this.setState({ articles: this.state.defaultData, selectedArticles: [] });
} else{
const currState = [...this.state.articles];
const newState = currState.filter(articles => !(articles.tags.tid.includes(parseInt(e.target.name))));
this.setState(prevState => ({
articles: newState,
selectedArticles: []
}));
}
}
}
};
tags_array[ 0: "130" 1: "231" 2: "232" 3: "233" 4: "226" ]
e.target.name = "130"
I'm getting Type error in const newState saying Cannot read property 'includes' of undefined
Aucun commentaire:
Enregistrer un commentaire