Error in React Router's link tag while switching from 0.14 to v15.5. This worked fine in the former version and it throws the following error in the latter.
Warning: React.createElement: 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. Check the render method of
Navbar
.
navbar.js
import React, { Component } from 'react';
import Link from 'react-router-dom';
class Navbar extends Component
{
render()
{
return (
<nav className="nav">
<Link className="btn btn-primary btn-block" to="/about">
About Us
</Link>
</nav>
);
}
export default Navbar;
index.js
import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter, Route, Switch } from 'react-router-dom';
import HomePage from './components/homepage/homepage';
import AboutPage from './components/aboutpage/aboutpage';
render
(
<BrowserRouter>
<Switch>
<Route path="/about" component={AboutPage} />
<Route path="/" component={HomePage} />
</Switch>
</BrowserRouter>,
document.getElementById('app')
);
createElement() React. createElement( type, [props], [... children] ) Create and return a new React element of the given type. The type argument can be either a tag name string (such as 'div' or 'span' ), a React component type (a class or a function), or a React fragment type.
Specifying The React Element Type Capitalized types indicate that the JSX tag is referring to a React component. These tags get compiled into a direct reference to the named variable, so if you use the JSX <Foo /> expression, Foo must be in scope.
JSX allows us to write HTML elements in JavaScript and place them in the DOM without any createElement() and/or appendChild() methods. JSX converts HTML tags into react elements. You are not required to use JSX, but JSX makes it easier to write React applications.
React Scope leverages React Developer Tools to retrieve information about the client's application. We then use this data to render a DOM tree visualization. The user simply hovers over the nodes within the tree to see each component's name, state, and props.
this error generally comes if you have not imported or exported a component successfully in your components.For more more info you can read react documentation of when to use curly braces while import and when not:)
import { Link } from "react-router-dom";
.
<ul>
<li><Link to="x">x</Link></li>
<li><Link to="y">y</Link></li>
<li><Link to="z">z</Link></li>
</ul>
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