简体   繁体   English

index.js:1 警告:React.createElement:类型无效

[英]index.js:1 Warning: React.createElement: type is invalid

here is the full error:这是完整的错误:

index.js:1 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, or you might have mixed up default and named imports.

here's the code from the exported HeaderSearchBox.js file:这是导出的 HeaderSearchBox.js 文件中的代码:

import React, { useState } from 'react';
import { Form, Button } from 'react-bootstrap';

const HeaderSearchBox = ({ history }) => {
 const [keyword, setKeyword] = useState('');

 const submitHandler = (e) => {
 e.preventDefault();
 if (keyword.trim()) {
  history.push(`/search/${keyword}`);
 } else {
  history.push('/');
}
};

return (
  <Form onSubmit={submitHandler} inline>
    <Form.Conrol
      type='text'
      name='q'
      onChange={(e) => setKeyword(e.target.value)}
      placeholder='Search Products.'
      className='mr-sm-2 ml-sm-5'
    ></Form.Conrol>
    <Button type='submit' variant='outline-success' className='p-2'>
      Search
    </Button>
  </Form>
  );
 };

 export default HeaderSearchBox;

and here is the code from the header file I'm trying to import the HeaderSearchBox to:这是我试图将 HeaderSearchBox 导入到的头文件中的代码:

import React from 'react';
import { Route } from 'react-router-dom'
import { useDispatch, useSelector } from 'react-redux';
import { LinkContainer } from 'react-router-bootstrap';
import { Navbar, Nav, Container, NavDropdown } from 'react-bootstrap';
import HeaderSearchBox from './HeaderSearchBox';
import { logout } from '../actions/userActions';


const Header = () => {
  const userLogin = useSelector((state) => state.userLogin);
  const { userInfo } = userLogin;

  const dispatch = useDispatch();

  const logoutHandler = () => {
    dispatch(logout());
  };

  return (
    <header>
      <Navbar bg='dark' variant='dark' expand='lg' collapseOnSelect>
        <Container>
          <LinkContainer to='/'>
            <Navbar.Brand>Shop</Navbar.Brand>
          </LinkContainer>
          <Navbar.Toggle aria-controls='basic-navbar-nav' />
          <Navbar.Collapse id='basic-navbar-nav'>
          <Route render={({ history }) => <HeaderSearchBox history={history} />} />
            <Nav className='ml-auto'>
              <LinkContainer to='/cart'>
                <Nav.Link>
                  <i className='fas fa-shopping-cart'></i> Cart
                </Nav.Link>
              </LinkContainer>
              {userInfo ? (
                <NavDropdown title={userInfo.name} id='username'>
                  <LinkContainer to='/profile'>
                    <NavDropdown.Item>Profile</NavDropdown.Item>
                  </LinkContainer>
                  <NavDropdown.Item onClick={logoutHandler}>
                    Logout
                  </NavDropdown.Item>
                </NavDropdown>
              ) : (
                <LinkContainer to='/login'>
                  <Nav.Link>
                    <i className='fas fa-user'></i> Sign in
                  </Nav.Link>
                </LinkContainer>
              )}
              {userInfo && userInfo.isAdmin && (
                <NavDropdown title='Admin' id='adminMenu'>
                  <LinkContainer to='/admin/userlist'>
                    <NavDropdown.Item>Users</NavDropdown.Item>
                  </LinkContainer>
                  <LinkContainer to='/admin/productlist'>
                    <NavDropdown.Item>Products</NavDropdown.Item>
                  </LinkContainer>
                  <LinkContainer to='/admin/orderlist'>
                    <NavDropdown.Item>Orders</NavDropdown.Item>
                  </LinkContainer>
                </NavDropdown>
              )}
            </Nav>
          </Navbar.Collapse>
        </Container>
      </Navbar>
    </header>
  );
};

export default Header;

I've tried removing the default export and use curly braces, and I also made sure the imports and exports are all named the same.我已经尝试删除默认导出并使用花括号,并且我还确保导入和导出的名称都相同。 I'm stumped, any help is appreciated我很难过,任何帮助表示赞赏

You have typo error here Form.Conrol => Form.Control你有错字错误Form.Conrol => Form.Control

<Form.Control
      type='text'
      name='q'
      onChange={(e) => setKeyword(e.target.value)}
      placeholder='Search Products.'
      className='mr-sm-2 ml-sm-5'
    ></Form.Control>

暂无
暂无

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

相关问题 React.createElement:类型无效-预期为字符串-index.js - React.createElement: type is invalid — expected a string — index.js React:警告:React.createElement:类型无效 - React: Warning: React.createElement: type is invalid 警告:React.createElement:type无效 - bundle.js - Warning: React.createElement: type is invalid — bundle.js React.createElement:类型无效 - 需要一个字符串(对于内置组件)。 在 Index.js 中使用 ContextProvider 时网页是空白的 - React.createElement: type is invalid -- expected a string (for built-in components). The webpage is blank when ContextProvider is used in Index.js 警告:React.createElement:类型在React Native Picker中无效 - Warning: React.createElement: type is invalid with React Native Picker 警告:React.createElement:类型无效——需要一个字符串 - Warning: React.createElement: type is invalid — expected a string 警告:React.createElement:类型无效 — expo reactnative app - Warning: React.createElement: type is invalid — expo reactnative app 警告:React.createElement:在组件中使用组件时类型无效 - Warning: React.createElement: type is invalid when using a component in a component 警告:React.createElement:类型无效——需要一个字符串 - Warning: React.createElement: type is invalid -- expected a string Popper.js React Wrapper - React.createElement:type无效 - Popper.js React Wrapper - React.createElement: type is invalid
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM