so the problem that you describe is that data is added to your component state when the component is re-rendered. in the code snipped you have supplied, you dont use any of the life cycle methods in react that can be triggered on re-renders. and i cannot see any other hooks that should trigger on a re-render. therefore i cant find any source to your problem.

however, i can see other issues that might make debugging harder for you. solving these might help you in nailing down the actual problem. in the componentdidmount method you call functions whose only purpose is to update the state. this is not good design since it will force the component to immediately re-render several times whenever it is mounted.

a better design is to fully prepare the chartdata-objekt in the constructor. for example, you could change your chartcolors function to take a chartdata object as a parameter, and return the new object with colors added. then make your constructor look something like this:

constructor(props) {

   const chartdatawithoutcolors = {
       labels: [],
       datasets: [
           //label: "quotes",
           data: [],
           backgroundcolor: []

   const chartdatawithcolor = this.chartcolors(chartdatawithoutcolors);

   this.state = {
     chartdata: chartdatawithcolor

by removing unnecessary calls to setstate you will make your components life both simpler and more performant. when you have simplified your component, start debugging by removing non-critical parts one at the time and try to nail down when your problem disappears. this should be sufficient to find the bug.

good luck!

Related Query

More Query from same tag