question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read properties of undefined (reading 'labels')

See original GitHub issue

I ccreated an Extra functional Linechart Component from the LineChart Example with React hooks.

Expected Behavior

const [chartData, setChartData] = useState({}); When using useState for initial value default {} should be accepted like in many other version/ tutorials and examples.

###Actual Behavior I get the error:

TypeError: Cannot read properties of undefined (reading ‘labels’).

What i tried so far

  1. setting a default with labels and Data
  2. using the Ternary Operator if chartData is undefined return (chartData)? <Line options={options} data={chartData} />:<Line options={options} data={chartData} />

Con of this solution getting an empty page only after 2 secs the Charts loads but normaly the usefect({//some code},[]);should be the initial load without an hinder the “emptyload”.

Operating System: Windows Browsers:

  1. Chromium(Opera,Chrome)
  2. Firefox

“react-chartjs-2”: “^4.0.0”, “react-dom”: “^17.0.2”, “react”: “^17.0.2”, “chart.js”: “^3.6.1”,

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
dangreencommented, Dec 3, 2021

@emilnobody Hi. datasets property is required, so as a default state, you can use

{
  datasets: []
}

If you still have problems, please provide issue reproduction by forking this sandbox.

0reactions
Oceanestarscommented, Dec 8, 2022

@emilnobody Hi. datasets property is required, so as a default state, you can use

{
  datasets: []
}

If you still have problems, please provide issue reproduction by forking this sandbox.

That fixed the error for me!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read properties of undefined (reading 'id')
I have this error in my terminal: TypeError: Cannot read properties of undefined (reading 'id').
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Uncaught TypeError: Cannot read property ... - Google Groups
I have checked the errores in the Console in Developer Tools and it shows the error "Uncaught TypeError: Cannot read property 'label' of...
Read more >
How to fix this " Uncaught TypeError: Cannot read properties ...
How to I fix this? Uncaught TypeError: Cannot read properties of undefined (reading 'mData'). ref my JQuery script: $.
Read more >
spModal error Cannot read properties of undefined...
Hi, I wanna use spModals on client script, but he always return the error : Cannot read properties of undefined (reading 'open'), ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found