Could you please help me to resolve the issue. I have already tried resolving the import functions but i still get that error and I have also tried to remove "{}" which didnt work. Thanks in advance. I am following TylerMcginnis React-Redux course. Navigation.js
import React from 'react'
import PropTypes from 'prop-types'
import Link from 'react-router-dom'
import { container, navContainer, link } from './styles.css'
Navigation.propTypes = ActionLinks.propTypes = NavLinks.propTypes = {
isAuthed: PropTypes.bool.isRequired,
}
function NavLinks ({isAuthed}) {
return (isAuthed === true
? <ul>
<li><Link to='/' className={link}>{'Home'}</Link></li>
</ul>
: <noscript />)
}
function ActionLinks ({isAuthed}) {
return (isAuthed === true
? <ul>
<li>NEW DUCK</li>
<li><Link to='/logout' className={link}>{'Logout'}</Link></li>
</ul>
: <ul>
<li><Link to='/' className={link}>{'Home'}</Link></li>
<li><Link to='/auth' className={link}>{'Authenticate'}</Link></li>
</ul>)
}
export default function Navigation ({isAuthed}) {
return (
<div className={container}>
<nav className={navContainer}>
<NavLinks isAuthed={isAuthed} />
<ActionLinks isAuthed={isAuthed} />
</nav>
</div>
)
}
MainContainer.js
import React from 'react'
import Navigation from '../../components/Navigation/Navigation'
import {container, innerContainer} from './styles.css'
import createReactClass from 'create-react-class'
const MainContainer = createReactClass({
render () {
return (
<div className={container}>
<Navigation isAuthed={true} />
<div className={innerContainer}>
{this.props.children}
</div>
</div>
)
},
})
export default MainContainer
error: Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports. at invariant (invariant.js:42)
To solve the error "Element type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got", make sure to import named exports using curly braces and default exports without, and only use functions or classes as components.
export default is used to export a single class, function or primitive from a script file. The export can also be written as export default class HelloWorld extends React.Component { render() { return <p>Hello, world!</
In my case, I was importing component as below so i was getting same error.
import { Calculator } from './src/calculator';
To fix it, i modified import as below and it worked.
import Calculator from './src/calculator';
@Harsha I had the same error. It took me an hour or so of hunting around making sure my code was correct, and so forth. I started tearing down the code I had, to make it as simple as possible, and then simpler still.
Finally, the issue was that I had copied an empty file into my component directory, but was coding in an identically named file in another directory. So I was importing an empty file. Of course it was going to be undefined. :(
Also, remember to put in semi-colons. ;)
The same hapenned to me. You are probably not saving the file. Maybe you are saving the App.js file but not the component file. I was saving the current file (ctrl+S) thinking I was saving all the files... I am using VS Code so I went to File/Preferences/Keyboard shortcuts and I set "Save all" to ctrl+shift+S.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With