I am getting the following error
//bundle.js:31367 Uncaught TypeError: this.setState is not a function//
JSX:
The problem is with Function Execution Scope.
componentDidMount(){
$.ajax({
...
}).done(function({data}){
///// HERE {this}
// try console.log(this);
// you will see there is no`setState`
this.setState({
lis1:[data.banner]
})
})
}
Now, function inside the done
chain, this
reference only inside the function.
componentDidMount(){
$.ajax({
url:'',
dataType:'json',
cache:false,
}).done(({data}) => {
this.setState({
lis1:[data.banner]
})
})
}