0
updateGame(e) {
 e.preventDefault();
 const game = {
  id: this.state.games.id,
  name: this.state.games.name,
  price: this.state.games.price,
  category: this.state.games.category
 }
 axios.put('https://localhost:5001/games/', game)
 .then(res => console.log(res.data)) 
}

I have two functions called Update and Delete. Delete is done, but need help with Update so I can change the content. Error

SuleymanSah
  • 17,153
  • 5
  • 33
  • 54
  • If `this` is `undefined`, it's probably related to how you're passing this method to whatever's calling it, which is *not included in your question*. Give a [mcve] (or, better, delete this and read https://stackoverflow.com/q/20279484/3001761). – jonrsharpe Nov 17 '19 at 15:19
  • Can you add all your component code to the question? – SuleymanSah Nov 17 '19 at 16:18

1 Answers1

0

In constructor of class. Try to bind context of updateGame like this:

constructor(props) {
   super(props);
   // This binding is necessary to make `this` work in the callback
   this.updateGame = this.updateGame.bind(this);
}

More information about Handling Event in React

aldenn
  • 2,060
  • 2
  • 11
  • 30