I am doing a React course here and the starter files keep giving me this error:
TypeError: Cannot read property '0' of undefined
From this starter code:
import React from 'react'
import ReactDOM from 'react-dom'
const notes = [
{
id: 1,
content: 'HTML is easy',
date: '2019-05-30T17:30:31.098Z',
important: true
},
{
id: 2,
content: 'Browser can execute only Javascript',
date: '2019-05-30T18:39:34.091Z',
important: false
},
{
id: 3,
content: 'GET and POST are the most important methods of HTTP protocol',
date: '2019-05-30T19:20:14.298Z',
important: true
}
]
const App = (props) => {
const { notes } = props
return (
<div>
<h1>Notes</h1>
<ul>
<li>{notes[0].content}</li>
<li>{notes[1].content}</li>
<li>{notes[2].content}</li>
</ul>
</div>
)
}
ReactDOM.render(
<App notes={notes} />,
document.getElementById('root')
)
Above code shows:
Attempted import error: './App' does not contain a default export (imported as 'App')
I tried amending by adding export default app and received:
TypeError: Cannot read property '0' of undefined
How can I solve this problem?
notesthat's declared outside your component to be the same as the one you are using inside, but can't tell unless you share the code where you are usingAppnotesas props toAppcomponent?