简体   繁体   English

反应错误:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义

[英]React Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined

I'm trying to create a simple page in react with some router, I get the following error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.我正在尝试创建一个简单的页面来与某些路由器做出反应,但出现以下错误:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义. APP.JS应用程序JS

import React, {Component} from 'react';
import {Route, BrowserRouter as Router, Switch, Link } from "react-router-dom"
import Contact from "./Contact"
import Tournoi from "./Tournoi"
import Home from "./Home"
import {NavigationBar} from "./components/NavigationBar"

class App extends Component{ 
render(){
  return (
    <React.Framgent> 
    <NavigationBar/> 
    <Router> 
    <Switch>
    <Route exact path="/" component={Home}/>
    <Route path="/Contact" component={Contact}/>
    <Route path="/Tournoi" component={Tournoi}/>
    </Switch>
    </Router>
    </React.Framgent>
  );
  }
}

export default App;

Index.js索引.js

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
);

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.

serviceWorker.unregister();

My component NavigationBar is not export by default howewer my other pages are我的组件 NavigationBar 默认不导出,但我的其他页面是

Navigation Bar导航栏

import React from 'react'
import {Nav,Navbar} from 'react-bootstrap';
import styled from "styled-components";
const Styles = styled.div `
.navbar {
    background-color: #222;
}
.navbar-brand .navbar-nav .nav-link{
    color:#bbb;
    &hover{
        color:white;
    }
}
`;
export const NavigationBar = () => (
<Styles>
    <Navbar expand="lg">
        <Navbar.Brand href="/"></Navbar.Brand>
        <Navbar.Toggle aria-controls="basic-navbar-nav"/>
        <Navbar.Collapse id="basic-navbar-nav">
            <Nav className="m1-auto">
                <Nav.Item><Nav.Link href="/">Home</Nav.Link> </Nav.Item>
                <Nav.Item><Nav.Link href="/Contact">Contact</Nav.Link> </Nav.Item>
                <Nav.Item><Nav.Link href="/Tournoi">Tournoi</Nav.Link> </Nav.Item>
            </Nav>
        </Navbar.Collapse>
    </Navbar>
</Styles>
)

My Pages structures is terribly simple我的页面结构非常简单


import React from 'react';

export default function Home (){
    return(
        <div className="Bannière1">
            <h1>Bienvenue vous êtes sur la page d'accueil</h1>
            <button> Créer un tournoi </button> <button>Voir notre générateur de Bracket</button>
            
            </div>
    )
}

You are probably using a version of React that did not yet have StrictMode .你可能正在使用一个还没有StrictMode的 React 版本。 It was introduced in React version 16.3 .它是在 React 版本16.3 中引入的。 React is complaining because React.StrictMode is returning undefined instead of the an actual component. React 抱怨是因为React.StrictMode返回的是undefined而不是实际的组件。 To confirm this, check the version of React in your package.json file.要确认这一点,请检查package.json文件中的 React 版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React - 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - React - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义的 React - Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined React 错误 - 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - error - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 错误:元素类型无效:需要一个字符串(对于内置组件)或一个类/函数(对于复合组件)但得到:未定义 - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 渲染错误元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义 - Render Error Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined 控制台错误:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义 - Console error: Element type is invalid:expected a string (for built-in components) or a class/function (for composite components) but got: undefined 未捕获的错误:元素类型无效:预期为字符串(内置组件)或类/函数(复合组件),但得到:未定义 - Uncaught Error: Element type is invalid: expected a string (built-in components) or a class/function ( composite components) but got: undefined 未捕获的错误:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:未定义 - Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got:undefined 错误:元素类型无效:应为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。 反应 - Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. React NextJS:元素类型无效:期望字符串(用于内置组件)或类/函数(用于复合组件)但得到:未定义 - NextJS: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM