-2

When I try running my code I get the error this.setState is not a function deos anyone know how I can correct this? Thanks!

spiele.listUsers(params, function(err, data) {
        if (err) console.log(err, err.stack);
        else     console.log(data)
        const ball = data;
        this.setState({
          ball
        }).bind(this)         
      });
jibidijib
  • 407
  • 2
  • 6
  • 16

1 Answers1

1

You are using .bind in the wrong place

spiele.listUsers(params, function(err, data) {
        if (err) console.log(err, err.stack);
        else     console.log(data)
        const ball = data;
        this.setState({
          ball
        }).bind(this)   // wrong      
      });

The .bind should be in function(err, data) not in this.setState

spiele.listUsers(params, function(err, data) {
        if (err) console.log(err, err.stack);
        else     console.log(data)
        const ball = data;
        this.setState({
          ball
        })       
      }.bind(this)); // correct
Vencovsky
  • 28,550
  • 17
  • 109
  • 176