TypeError: Cannot read properties of undefined (reading 'labels')
See original GitHub issueI 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
- setting a default with labels and Data
- 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:
- Chromium(Opera,Chrome)
- Firefox
“react-chartjs-2”: “^4.0.0”, “react-dom”: “^17.0.2”, “react”: “^17.0.2”, “chart.js”: “^3.6.1”,
Issue Analytics
- State:
- Created 2 years ago
- Comments:6
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@emilnobody Hi.
datasets
property is required, so as a default state, you can useIf you still have problems, please provide issue reproduction by forking this sandbox.
That fixed the error for me!