Harsh Thakur
Harsh Thakur

Reputation: 1

TypeError: Cannot read property 'includes' of undefined - Error in chrome after successfully compiling

I compiled a react code and it was showing successful compiled in my terminal but i don't know why this error is coming on chrome.

This is the code:

render() {
    const filteredRobots =this.state.robots.filter(robot => {
        return (robots.name.**includes**( this.state.serchfeild ))
    }) 

}

Upvotes: 0

Views: 153

Answers (1)

explorer
explorer

Reputation: 23

You have used wrong variable name inside arrow function. You need to use robot.name instead of robots.name. Below is correct code:

render() {
    const filteredRobots =this.state.robots.filter(robot => {
        return (robot.name.includes( this.state.serchfeild ))
    })  
}

Upvotes: 1

Related Questions