2

I'm making a simple react app where I use Fusioncharts to render two charts. Just as given in the Fusioncharts example, I'm trying to mutate the state of one chart (Column chart) based on the input from the another(piechart). The problem is, I have a common ancestor for both the components. Content is a parent of Dash and topcontent. So the pie chart is in dash component, I use a callback prop (onslice) to call the parent component's function and I set state of parent to mutate the prop sent to the column chart via topcontent. Here's the code.

filtercallback(c,k){
console.log("In callback",c,k); 
// this shows up which means the call was successful
this.setState({  filtertext: c,filtersource:k  },function()   
                 {  // Callback function
               console.log("callback by",c,k);
             // this doesn't show up and state isn't set
                });

For whatever reason, the state isn't being set. And the callback containing console.log() also isn't logging anything. Can someone help?

Arvind
  • 730
  • 10
  • 20

1 Answers1

9

You probably are missing binding to this for the filtercallBack. Try in your constructor to set:

this.filtercallBack = this.filtercallBack.bind(this);

Assuming it is a class function.

Janne
  • 1,665
  • 15
  • 22