I have this code in my quotes component:
componentWillMount(){
QuoteStore.on("newQuoteAdded",this.getQuotes);
}
componentWillUnmount(){
QuoteStore.removeListener("newQuoteAdded",this.getQuotes);
}
getQuotes(){
console.log(this);
this.setState({
quotes:QuoteStore.getQuotes()
});
}
An event is emitted when new data is added to the flux store (QuoteStore) like this
addQuote(quote,author){
const newQuote=new Object();
const date=Date.now().toString();
newQuote.id=date;
newQuote.author=author;
newQuote.quote=quote;
this.Quotes.push(newQuote);
this.emit("newQuoteAdded");
}
I am getting this error when my component actually captures this event :
this.setState is not a function at QuoteStore.getQuotes
Can anyone help, how can I bind my this to Quotes component in getQuotes() callback on event capturing?