Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
searchItems() {
const query = this.state.search;
if (!query || query.length < 3)
return this.setState({filteredItems: []});
const regex = new RegExp(escapeRegexp(query).replace(/\s/g, '\\s'), 'i');
const filteredItems = (this.props.paragraphs || [])
.filter(data => {
return regex.test(data.paragraph.text);
});
return this.setState({filteredItems: filteredItems});
}
searchItems() {
const query = this.state.search;
if (!query || query.length < 3)
return this.setState({filteredItems: []});
const regex = new RegExp(escapeRegexp(query).replace(/\s/g, '\\s'), 'i');
const filteredItems = (this.props.voc || [])
.filter(voc => {
if (regex.test(voc.title))
return true;
return voc.children.some(paragraph => {
return regex.test(paragraph.text);
});
});
return this.setState({filteredItems: filteredItems});
}