1

I can't get it to respond onDoubleClick. neither with console.log. I do not understand why, since the code looks good. I hope your help thank you very much, bye.

}

deleteUser = async(id) => {

    await axios.delete('http://localhost:4000/users/' + id)
    this.getUsers();

}

                           this.state.users.map(user => (
                            <li 
                                className="list-group-item list-group-item-action" 
                                key={user._id}
                                onDoubleClick={() => this.deleteUser(user._id)}
                                >
                                {user.username}
                            </li>)
                        )


                           
  • 1
    Can you create a working code snippet where this doesn't work? [This answer](https://meta.stackoverflow.com/questions/338537/how-do-i-create-a-react-stack-snippet-with-jsx-support) can help with it – Anurag Srivastava Jul 04 '20 at 18:17

2 Answers2

0

Here you need to bind your method before using in template

this.doublemethod = this.doublemethod.bind(this); // in your constructor

Note: https://stackblitz.com/edit/react-juq9t6

-1

Add .bind(this) hope you achieve what you want.

 <li className="list-group-item list-group-item-action" 
      key={user._id}
      onDoubleClick={ this.deleteUser(user._id).bind(this)}>
      {user.username}
 </li>
GMKHussain
  • 3,342
  • 1
  • 21
  • 19