简体   繁体   中英

How to fix Render Error createElement() in JSX in React

I am trying to render my <App /> component and I keep getting TypeError: cannot read property createElement of undefined in the <Home /> , <Navbar /> and <Login /> components, when I try to compile the project. All errors indicate Line 9 in Index.js Here is what it contains:

Login.js Line 3

import { React } from "react";

const Login = () => (
  <div>
    ...

Home.js Line 4

import { React } from "react";
import { Link } from "react-router-dom";

const Home = () => (
  <div className="jumbotron">
 ...

Navbar.js Line 6

import { React } from "react";
import { NavLink } from "react-router-dom";

function Navbar() {
  const activeStyle = { color: "#F15B2A" };
  return (
    <nav>
    ...

I am interested in understanding why I keep getting errors at the component declaration in these components or is it something related to the return and render methods and how I call them?

Since you're rendering JSX in your component declaration files, you need to import React (default import) so that the JSX is recognized.

Change the following lines in all your files from:

import { React } from 'react'

to import React like this: (without brackets).

import React from 'react'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM