score:0

Accepted answer

for your first trial, try to remove curly brackets at charttobedisplayed.

{this.state.isloaded ? charttobedisplayed : <div>loading...</div>}

as long as the grammar of your chart is correct, it should work.


for your second trial.

chart.js only set state at initial mount.

thus, when you update state on app.js and pass new props - charttype to chart.js, you need to update the local state.

try to add componentwillreceiveprops at chart.js component.

class chart extends component {
  constructor(props) {
    ...
  }

  componentwillreceiveprops(nextprops) {
    if (nextprops.charttype !== this.state.charttype) {
      this.setstate({charttype: nextprops.charttype})
    }
  }
}

updated

for preventing misunderstand, chart.js mentioned above means the chart.js file posted on question.


Related Query

More Query from same tag