yandex
loader

please wait

  • Liza Sain Dec-24-2018 05:50:43 AM ( 2 months ago )

    I am creating a project in react js.When fetching the product list from product api and iterating it in html page using loop.I am not able to call the functions with this keywork.I am getting the following error.

     

    :'this' is null

     

    My code is as below:

     

    {this.state.items.map(function(item, index){

    return(

    {this.onLoads();this.props.history.push('/product-detail')}}>

    {

    item.product_image?

    :

    }

     

     

     

    this.props.history.push('/product-detail')}>{item.product_name}{item.product_description=item.product_description.replace(/<(.|\n)*?>/g, '')}

     

    {item.product_point} Points

                  

     

     

    )

    }

    ) }

  • Rahul Chaudhary Dec-24-2018 05:56:25 AM ( 2 months ago )

    Instead of using vanilla function use thigh arrow function like see below:

    Replace this:

    {this.state.items.map(function(item, index){

     

    By:

     

    {this.state.items.map((item, index)=>{

Please login

Similar Discussion

Recommended For You