Hello,
I’m trying to create a local search functionality in my react.js application. However, I am having issues with the search function itself. Below is the code block i’m running and the error i’m getting:
const business1 = {
imageSrc: ‘https://s3.amazonaws.com/codecademy-content/programs/react/ravenous/pizza.jpg’,
name: ‘MarginOtto Pizzeria’,
address: ‘1010 Paddington Way’,
city: ‘Bordertown’
};
const business2 = {
imageSrc: ‘https://s3.amazonaws.com/codecademy-content/programs/react/ravenous/pizza.jpg’,
name: ‘MarginOtto Pizzeria’,
address: ‘1010 Paddington Way’,
city: ‘Bordertown’
};
const businesses = [
business1,
business2
];
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
searchResults: []
};
this.search = this.search.bind(this);
}
search(term) {
let results = this.state.searchResults;
businesses.map((business) => {
Object.keys(business).map(function (key) {
if (business[key].includes(term)) {
results.push(business);
this.setState({searchResults: results});
}
})
})
}
Error: