Hello,
I'm getting the error in the title but I can't figure out the reason.
In my React app, I have this line of code inside the render():
<Bar data={this.state.arduData} width={100} height={50} options={{ maintainAspectRatio: false }} />
and also in my this.state.arduData I've stored an array like this one: {
labels: ['a','b','c','d'],
datasets: {
label:Data from arduino ${this.state.selectedArduino},
data: [1,2,3,4]
}
I have a state property called data, maybe I'm having problems due that? Thanks in advance
@alexgbor I was having the same issue. In my component that calls <Bar />, I was initializing the state like this:
this.state = { data: [] };
and updating the state in componentDidMount(). This initialization was throwing an error: ChartComponent requires an object type and not an array type.
I switched my state initialization to this:
this.state = {
data: { datasets:[], labels:[] }
}
and I'm no longer getting the error in console.
Try outputting to console what your this.state.arduData value is during render() and see if this is what I was running into. Hope that helps!
EDIT: fixed my garbage formatting
That was exactly my problem. Thanks man
Most helpful comment
@alexgbor I was having the same issue. In my component that calls
<Bar />, I was initializing the state like this:this.state = { data: [] };and updating the state in
componentDidMount(). This initialization was throwing an error: ChartComponent requires anobjecttype and not anarraytype.I switched my state initialization to this:
this.state = { data: { datasets:[], labels:[] } }and I'm no longer getting the error in console.
Try outputting to
consolewhat yourthis.state.arduDatavalue is duringrender()and see if this is what I was running into. Hope that helps!EDIT: fixed my garbage formatting