React TypeError: “_this2.setState is not a function”?












0














I know this question is getting asked a lot and I did check most of the other answers provided but I still can't find out why I get this error.



Situation:



I have my textinput class in which I have a simple form for the user to input a name. When the user submits the button a REST call to my backend is called and the UI should show the user's name.



I have overridden the function componentDidMount of my App class to have an initial call to my backend when the page is loaded. This call works and I get the correct answer from my backend and the UI gets updated.



But when i make the call from my TextInput class, I get the error:




this2.setState is not a function




I believe that this is happening because I call the function from another class and the this state is not set correctly. I tried to bind all the things but that did not change anything. If anyone has an idea of what I am doing wrong, it would be very helpful!



I have the following classes:



import React, { Component } from 'react';
import logo from './logo.svg';
import Greeting from './components/greeting';
import TextInput from './components/textInput';
import './App.css';

const axios = require('axios');

class App extends Component {
constructor(props) {
super(props);
this.state = {name: "World"};
this.getFormattedNameFromBackend.bind(this);
this.setState.bind(this);
}

componentDidMount() {
this.getFormattedNameFromBackend(this.state.name);
}

getFormattedNameFromBackend(name) {
axios({
method:'get',
url:'http://localhost:8080/hello?name=' + name
}).then((response) => {
this.setState({ name : response.data.name});
}).catch(function(error){
console.log(error);
});
}


render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<Greeting data={this.state}/>
<TextInput callBack = {this.getFormattedNameFromBackend}/>
</header>
</div>
);
}

}

export default App;


This is the main class where I get the error in the axios rest call.



the second class is this:



import React, { Component } from 'react';

export default class TextInput extends Component {
constructor(props) {
super(props);
this.state = {value: ''};

this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

handleChange(event) {
this.setState({value: event.target.value});
}

handleSubmit(event) {
this.props.callBack(this.state.value);

event.preventDefault();
}

render() {
return (
<form onSubmit= {this.handleSubmit}>
<label>
Name:
<input type="text" value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Submit" />
</form>
);
}
}


so the Question is, how do i call the correct this in the method getFormattedNameFromBackend?



Solved:



the mistake was setting the props of the Textinputfield wrong. Correctly it should be



<TextInput callBack = {(name)=>this.getFormattedNameFromBackend(name)}/>









share|improve this question
























  • Sounds like this is referencing the wrong object. Try printing what this is where it raises, or reading this stackoverflow.com/questions/45041878/closures-in-react In short, events in render function act on event objects and not on the class that the render function is defined on, that is because events are async...
    – Daniel Dubovski
    Nov 11 at 13:56












  • at the time i get the error "this" is an object of type textinput. But how to i change that?
    – Marcus Lanvers
    Nov 11 at 13:58










  • Try looking at the link I provided, easiest way would be to bind it via closure onSubmit= (e) => {this.handleSubmit(e)}. Take a look at this as well : reactjs.org/docs/handling-events.html
    – Daniel Dubovski
    Nov 11 at 13:59












  • i am trying this but that actually gives me syntax errors. :/ I am trying this now: onSubmit={(e)=>this.handleSubmit(e)} but that gives me the same error i had before
    – Marcus Lanvers
    Nov 11 at 14:03








  • 1




    take a look at this, it seems to be working jsfiddle.net/n5u2wwjg/233958
    – Daniel Dubovski
    Nov 11 at 14:18
















0














I know this question is getting asked a lot and I did check most of the other answers provided but I still can't find out why I get this error.



Situation:



I have my textinput class in which I have a simple form for the user to input a name. When the user submits the button a REST call to my backend is called and the UI should show the user's name.



I have overridden the function componentDidMount of my App class to have an initial call to my backend when the page is loaded. This call works and I get the correct answer from my backend and the UI gets updated.



But when i make the call from my TextInput class, I get the error:




this2.setState is not a function




I believe that this is happening because I call the function from another class and the this state is not set correctly. I tried to bind all the things but that did not change anything. If anyone has an idea of what I am doing wrong, it would be very helpful!



I have the following classes:



import React, { Component } from 'react';
import logo from './logo.svg';
import Greeting from './components/greeting';
import TextInput from './components/textInput';
import './App.css';

const axios = require('axios');

class App extends Component {
constructor(props) {
super(props);
this.state = {name: "World"};
this.getFormattedNameFromBackend.bind(this);
this.setState.bind(this);
}

componentDidMount() {
this.getFormattedNameFromBackend(this.state.name);
}

getFormattedNameFromBackend(name) {
axios({
method:'get',
url:'http://localhost:8080/hello?name=' + name
}).then((response) => {
this.setState({ name : response.data.name});
}).catch(function(error){
console.log(error);
});
}


render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<Greeting data={this.state}/>
<TextInput callBack = {this.getFormattedNameFromBackend}/>
</header>
</div>
);
}

}

export default App;


This is the main class where I get the error in the axios rest call.



the second class is this:



import React, { Component } from 'react';

export default class TextInput extends Component {
constructor(props) {
super(props);
this.state = {value: ''};

this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

handleChange(event) {
this.setState({value: event.target.value});
}

handleSubmit(event) {
this.props.callBack(this.state.value);

event.preventDefault();
}

render() {
return (
<form onSubmit= {this.handleSubmit}>
<label>
Name:
<input type="text" value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Submit" />
</form>
);
}
}


so the Question is, how do i call the correct this in the method getFormattedNameFromBackend?



Solved:



the mistake was setting the props of the Textinputfield wrong. Correctly it should be



<TextInput callBack = {(name)=>this.getFormattedNameFromBackend(name)}/>









share|improve this question
























  • Sounds like this is referencing the wrong object. Try printing what this is where it raises, or reading this stackoverflow.com/questions/45041878/closures-in-react In short, events in render function act on event objects and not on the class that the render function is defined on, that is because events are async...
    – Daniel Dubovski
    Nov 11 at 13:56












  • at the time i get the error "this" is an object of type textinput. But how to i change that?
    – Marcus Lanvers
    Nov 11 at 13:58










  • Try looking at the link I provided, easiest way would be to bind it via closure onSubmit= (e) => {this.handleSubmit(e)}. Take a look at this as well : reactjs.org/docs/handling-events.html
    – Daniel Dubovski
    Nov 11 at 13:59












  • i am trying this but that actually gives me syntax errors. :/ I am trying this now: onSubmit={(e)=>this.handleSubmit(e)} but that gives me the same error i had before
    – Marcus Lanvers
    Nov 11 at 14:03








  • 1




    take a look at this, it seems to be working jsfiddle.net/n5u2wwjg/233958
    – Daniel Dubovski
    Nov 11 at 14:18














0












0








0







I know this question is getting asked a lot and I did check most of the other answers provided but I still can't find out why I get this error.



Situation:



I have my textinput class in which I have a simple form for the user to input a name. When the user submits the button a REST call to my backend is called and the UI should show the user's name.



I have overridden the function componentDidMount of my App class to have an initial call to my backend when the page is loaded. This call works and I get the correct answer from my backend and the UI gets updated.



But when i make the call from my TextInput class, I get the error:




this2.setState is not a function




I believe that this is happening because I call the function from another class and the this state is not set correctly. I tried to bind all the things but that did not change anything. If anyone has an idea of what I am doing wrong, it would be very helpful!



I have the following classes:



import React, { Component } from 'react';
import logo from './logo.svg';
import Greeting from './components/greeting';
import TextInput from './components/textInput';
import './App.css';

const axios = require('axios');

class App extends Component {
constructor(props) {
super(props);
this.state = {name: "World"};
this.getFormattedNameFromBackend.bind(this);
this.setState.bind(this);
}

componentDidMount() {
this.getFormattedNameFromBackend(this.state.name);
}

getFormattedNameFromBackend(name) {
axios({
method:'get',
url:'http://localhost:8080/hello?name=' + name
}).then((response) => {
this.setState({ name : response.data.name});
}).catch(function(error){
console.log(error);
});
}


render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<Greeting data={this.state}/>
<TextInput callBack = {this.getFormattedNameFromBackend}/>
</header>
</div>
);
}

}

export default App;


This is the main class where I get the error in the axios rest call.



the second class is this:



import React, { Component } from 'react';

export default class TextInput extends Component {
constructor(props) {
super(props);
this.state = {value: ''};

this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

handleChange(event) {
this.setState({value: event.target.value});
}

handleSubmit(event) {
this.props.callBack(this.state.value);

event.preventDefault();
}

render() {
return (
<form onSubmit= {this.handleSubmit}>
<label>
Name:
<input type="text" value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Submit" />
</form>
);
}
}


so the Question is, how do i call the correct this in the method getFormattedNameFromBackend?



Solved:



the mistake was setting the props of the Textinputfield wrong. Correctly it should be



<TextInput callBack = {(name)=>this.getFormattedNameFromBackend(name)}/>









share|improve this question















I know this question is getting asked a lot and I did check most of the other answers provided but I still can't find out why I get this error.



Situation:



I have my textinput class in which I have a simple form for the user to input a name. When the user submits the button a REST call to my backend is called and the UI should show the user's name.



I have overridden the function componentDidMount of my App class to have an initial call to my backend when the page is loaded. This call works and I get the correct answer from my backend and the UI gets updated.



But when i make the call from my TextInput class, I get the error:




this2.setState is not a function




I believe that this is happening because I call the function from another class and the this state is not set correctly. I tried to bind all the things but that did not change anything. If anyone has an idea of what I am doing wrong, it would be very helpful!



I have the following classes:



import React, { Component } from 'react';
import logo from './logo.svg';
import Greeting from './components/greeting';
import TextInput from './components/textInput';
import './App.css';

const axios = require('axios');

class App extends Component {
constructor(props) {
super(props);
this.state = {name: "World"};
this.getFormattedNameFromBackend.bind(this);
this.setState.bind(this);
}

componentDidMount() {
this.getFormattedNameFromBackend(this.state.name);
}

getFormattedNameFromBackend(name) {
axios({
method:'get',
url:'http://localhost:8080/hello?name=' + name
}).then((response) => {
this.setState({ name : response.data.name});
}).catch(function(error){
console.log(error);
});
}


render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<Greeting data={this.state}/>
<TextInput callBack = {this.getFormattedNameFromBackend}/>
</header>
</div>
);
}

}

export default App;


This is the main class where I get the error in the axios rest call.



the second class is this:



import React, { Component } from 'react';

export default class TextInput extends Component {
constructor(props) {
super(props);
this.state = {value: ''};

this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}

handleChange(event) {
this.setState({value: event.target.value});
}

handleSubmit(event) {
this.props.callBack(this.state.value);

event.preventDefault();
}

render() {
return (
<form onSubmit= {this.handleSubmit}>
<label>
Name:
<input type="text" value={this.state.value} onChange={this.handleChange} />
</label>
<input type="submit" value="Submit" />
</form>
);
}
}


so the Question is, how do i call the correct this in the method getFormattedNameFromBackend?



Solved:



the mistake was setting the props of the Textinputfield wrong. Correctly it should be



<TextInput callBack = {(name)=>this.getFormattedNameFromBackend(name)}/>






javascript reactjs axios






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 14:25

























asked Nov 11 at 13:48









Marcus Lanvers

639




639












  • Sounds like this is referencing the wrong object. Try printing what this is where it raises, or reading this stackoverflow.com/questions/45041878/closures-in-react In short, events in render function act on event objects and not on the class that the render function is defined on, that is because events are async...
    – Daniel Dubovski
    Nov 11 at 13:56












  • at the time i get the error "this" is an object of type textinput. But how to i change that?
    – Marcus Lanvers
    Nov 11 at 13:58










  • Try looking at the link I provided, easiest way would be to bind it via closure onSubmit= (e) => {this.handleSubmit(e)}. Take a look at this as well : reactjs.org/docs/handling-events.html
    – Daniel Dubovski
    Nov 11 at 13:59












  • i am trying this but that actually gives me syntax errors. :/ I am trying this now: onSubmit={(e)=>this.handleSubmit(e)} but that gives me the same error i had before
    – Marcus Lanvers
    Nov 11 at 14:03








  • 1




    take a look at this, it seems to be working jsfiddle.net/n5u2wwjg/233958
    – Daniel Dubovski
    Nov 11 at 14:18


















  • Sounds like this is referencing the wrong object. Try printing what this is where it raises, or reading this stackoverflow.com/questions/45041878/closures-in-react In short, events in render function act on event objects and not on the class that the render function is defined on, that is because events are async...
    – Daniel Dubovski
    Nov 11 at 13:56












  • at the time i get the error "this" is an object of type textinput. But how to i change that?
    – Marcus Lanvers
    Nov 11 at 13:58










  • Try looking at the link I provided, easiest way would be to bind it via closure onSubmit= (e) => {this.handleSubmit(e)}. Take a look at this as well : reactjs.org/docs/handling-events.html
    – Daniel Dubovski
    Nov 11 at 13:59












  • i am trying this but that actually gives me syntax errors. :/ I am trying this now: onSubmit={(e)=>this.handleSubmit(e)} but that gives me the same error i had before
    – Marcus Lanvers
    Nov 11 at 14:03








  • 1




    take a look at this, it seems to be working jsfiddle.net/n5u2wwjg/233958
    – Daniel Dubovski
    Nov 11 at 14:18
















Sounds like this is referencing the wrong object. Try printing what this is where it raises, or reading this stackoverflow.com/questions/45041878/closures-in-react In short, events in render function act on event objects and not on the class that the render function is defined on, that is because events are async...
– Daniel Dubovski
Nov 11 at 13:56






Sounds like this is referencing the wrong object. Try printing what this is where it raises, or reading this stackoverflow.com/questions/45041878/closures-in-react In short, events in render function act on event objects and not on the class that the render function is defined on, that is because events are async...
– Daniel Dubovski
Nov 11 at 13:56














at the time i get the error "this" is an object of type textinput. But how to i change that?
– Marcus Lanvers
Nov 11 at 13:58




at the time i get the error "this" is an object of type textinput. But how to i change that?
– Marcus Lanvers
Nov 11 at 13:58












Try looking at the link I provided, easiest way would be to bind it via closure onSubmit= (e) => {this.handleSubmit(e)}. Take a look at this as well : reactjs.org/docs/handling-events.html
– Daniel Dubovski
Nov 11 at 13:59






Try looking at the link I provided, easiest way would be to bind it via closure onSubmit= (e) => {this.handleSubmit(e)}. Take a look at this as well : reactjs.org/docs/handling-events.html
– Daniel Dubovski
Nov 11 at 13:59














i am trying this but that actually gives me syntax errors. :/ I am trying this now: onSubmit={(e)=>this.handleSubmit(e)} but that gives me the same error i had before
– Marcus Lanvers
Nov 11 at 14:03






i am trying this but that actually gives me syntax errors. :/ I am trying this now: onSubmit={(e)=>this.handleSubmit(e)} but that gives me the same error i had before
– Marcus Lanvers
Nov 11 at 14:03






1




1




take a look at this, it seems to be working jsfiddle.net/n5u2wwjg/233958
– Daniel Dubovski
Nov 11 at 14:18




take a look at this, it seems to be working jsfiddle.net/n5u2wwjg/233958
– Daniel Dubovski
Nov 11 at 14:18












2 Answers
2






active

oldest

votes


















0














In case anyone else reaches this question, https://reactjs.org/docs/handling-events.html explains quite well why this happens.



In short, this is not bound when event callbacks are invoked.



The easiest way to fix this is by enclosing this :
onSubmit={(e) => {this.handleSubmit(e)} (altough this those create a new function instance each time, so need to be careful when using this method).






share|improve this answer





























    0














    The way you solved it works by simply avoiding the binding if this altogether, but your original problem was that the line



        this.getFormattedNameFromBackend.bind(this);


    doesn't do exactly what you think it does.
    .bind() returns a new function that wraps the original function, but you're not doing anything with that new function. .bind() doesn't modify the original function so this.getFormattedNameFromBackend remains unbound and that's why <TextInput callBack = {this.getFormattedNameFromBackend}/> didn't work.



    If you had written that line as:



        this.getFormattedNameFromBackend = this.getFormattedNameFromBackend.bind(this);


    ...(like you do in your TextInput class) it would get bound properly and callBack = {this.getFormattedNameFromBackend} would work.



    Like I said, by writing it as callBack = {() => this.getFormattedNameFromBackend()} you're avoiding the binding issue anyway so you can simply remove this.getFormattedNameFromBackend.bind(this); (and BTW, this.setState.bind(this); is pretty pointless too)






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249393%2freact-typeerror-this2-setstate-is-not-a-function%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      In case anyone else reaches this question, https://reactjs.org/docs/handling-events.html explains quite well why this happens.



      In short, this is not bound when event callbacks are invoked.



      The easiest way to fix this is by enclosing this :
      onSubmit={(e) => {this.handleSubmit(e)} (altough this those create a new function instance each time, so need to be careful when using this method).






      share|improve this answer


























        0














        In case anyone else reaches this question, https://reactjs.org/docs/handling-events.html explains quite well why this happens.



        In short, this is not bound when event callbacks are invoked.



        The easiest way to fix this is by enclosing this :
        onSubmit={(e) => {this.handleSubmit(e)} (altough this those create a new function instance each time, so need to be careful when using this method).






        share|improve this answer
























          0












          0








          0






          In case anyone else reaches this question, https://reactjs.org/docs/handling-events.html explains quite well why this happens.



          In short, this is not bound when event callbacks are invoked.



          The easiest way to fix this is by enclosing this :
          onSubmit={(e) => {this.handleSubmit(e)} (altough this those create a new function instance each time, so need to be careful when using this method).






          share|improve this answer












          In case anyone else reaches this question, https://reactjs.org/docs/handling-events.html explains quite well why this happens.



          In short, this is not bound when event callbacks are invoked.



          The easiest way to fix this is by enclosing this :
          onSubmit={(e) => {this.handleSubmit(e)} (altough this those create a new function instance each time, so need to be careful when using this method).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 14:29









          Daniel Dubovski

          1,0231223




          1,0231223

























              0














              The way you solved it works by simply avoiding the binding if this altogether, but your original problem was that the line



                  this.getFormattedNameFromBackend.bind(this);


              doesn't do exactly what you think it does.
              .bind() returns a new function that wraps the original function, but you're not doing anything with that new function. .bind() doesn't modify the original function so this.getFormattedNameFromBackend remains unbound and that's why <TextInput callBack = {this.getFormattedNameFromBackend}/> didn't work.



              If you had written that line as:



                  this.getFormattedNameFromBackend = this.getFormattedNameFromBackend.bind(this);


              ...(like you do in your TextInput class) it would get bound properly and callBack = {this.getFormattedNameFromBackend} would work.



              Like I said, by writing it as callBack = {() => this.getFormattedNameFromBackend()} you're avoiding the binding issue anyway so you can simply remove this.getFormattedNameFromBackend.bind(this); (and BTW, this.setState.bind(this); is pretty pointless too)






              share|improve this answer


























                0














                The way you solved it works by simply avoiding the binding if this altogether, but your original problem was that the line



                    this.getFormattedNameFromBackend.bind(this);


                doesn't do exactly what you think it does.
                .bind() returns a new function that wraps the original function, but you're not doing anything with that new function. .bind() doesn't modify the original function so this.getFormattedNameFromBackend remains unbound and that's why <TextInput callBack = {this.getFormattedNameFromBackend}/> didn't work.



                If you had written that line as:



                    this.getFormattedNameFromBackend = this.getFormattedNameFromBackend.bind(this);


                ...(like you do in your TextInput class) it would get bound properly and callBack = {this.getFormattedNameFromBackend} would work.



                Like I said, by writing it as callBack = {() => this.getFormattedNameFromBackend()} you're avoiding the binding issue anyway so you can simply remove this.getFormattedNameFromBackend.bind(this); (and BTW, this.setState.bind(this); is pretty pointless too)






                share|improve this answer
























                  0












                  0








                  0






                  The way you solved it works by simply avoiding the binding if this altogether, but your original problem was that the line



                      this.getFormattedNameFromBackend.bind(this);


                  doesn't do exactly what you think it does.
                  .bind() returns a new function that wraps the original function, but you're not doing anything with that new function. .bind() doesn't modify the original function so this.getFormattedNameFromBackend remains unbound and that's why <TextInput callBack = {this.getFormattedNameFromBackend}/> didn't work.



                  If you had written that line as:



                      this.getFormattedNameFromBackend = this.getFormattedNameFromBackend.bind(this);


                  ...(like you do in your TextInput class) it would get bound properly and callBack = {this.getFormattedNameFromBackend} would work.



                  Like I said, by writing it as callBack = {() => this.getFormattedNameFromBackend()} you're avoiding the binding issue anyway so you can simply remove this.getFormattedNameFromBackend.bind(this); (and BTW, this.setState.bind(this); is pretty pointless too)






                  share|improve this answer












                  The way you solved it works by simply avoiding the binding if this altogether, but your original problem was that the line



                      this.getFormattedNameFromBackend.bind(this);


                  doesn't do exactly what you think it does.
                  .bind() returns a new function that wraps the original function, but you're not doing anything with that new function. .bind() doesn't modify the original function so this.getFormattedNameFromBackend remains unbound and that's why <TextInput callBack = {this.getFormattedNameFromBackend}/> didn't work.



                  If you had written that line as:



                      this.getFormattedNameFromBackend = this.getFormattedNameFromBackend.bind(this);


                  ...(like you do in your TextInput class) it would get bound properly and callBack = {this.getFormattedNameFromBackend} would work.



                  Like I said, by writing it as callBack = {() => this.getFormattedNameFromBackend()} you're avoiding the binding issue anyway so you can simply remove this.getFormattedNameFromBackend.bind(this); (and BTW, this.setState.bind(this); is pretty pointless too)







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 11 at 15:01









                  Lennholm

                  4,3081823




                  4,3081823






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53249393%2freact-typeerror-this2-setstate-is-not-a-function%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      這個網誌中的熱門文章

                      Tangent Lines Diagram Along Smooth Curve

                      Yusuf al-Mu'taman ibn Hud

                      Zucchini