我正在尝试使用React-Bootstrap中的“ InputGroup”。但是,当我使用InputGroup.Prepend时,出现一条错误消息:
元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件),但得到:未定义。您可能忘记了从定义文件中导出组件,或者可能混淆了默认导入和命名导入。
我从遭受类似问题的人们那里了解到,默认的导出方法或某些导入会导致这些行为。但是,将这些解决方案应用于此问题并没有取得预期的结果。
这是我的“ test.js”
import React, { Component } from "react";
import { FormControl, InputGroup } from "react-bootstrap";
export default class Test extends Component {
render() {
return (
<div className="Home">
<InputGroup className="mb-3">
<InputGroup.Prepend>
<InputGroup.Text id="basic-addon1">@</InputGroup.Text>
</InputGroup.Prepend>
<FormControl
placeholder="Username"
aria-label="Username"
aria-describedby="basic-addon1"
/>
</InputGroup>
</div>
);
}
}
还有我的App.js
import React, { useState, useEffect } from "react";
import { Auth } from "aws-amplify";
import { Link, withRouter } from "react-router-dom";
import { Nav, Navbar, NavItem } from "react-bootstrap";
import { LinkContainer } from "react-router-bootstrap";
import Routes from "./Routes";
import "./App.css";
function App(props) {
const [isAuthenticating, setIsAuthenticating] = useState(true);
const [isAuthenticated, userHasAuthenticated] = useState(false);
useEffect(() => {
onLoad();
}, []);
async function onLoad() {
try {
await Auth.currentSession();
userHasAuthenticated(true);
}
catch(e) {
if (e !== 'No current user') {
alert(e);
}
}
setIsAuthenticating(false);
}
async function handleLogout() {
await Auth.signOut();
userHasAuthenticated(false);
props.history.push("/login");
}
return (
!isAuthenticating && (
<div className="App container">
<Navbar fluid collapseOnSelect>
<Navbar.Header>
<Navbar.Brand>
<Link to="/">Scratch</Link>
</Navbar.Brand>
<Navbar.Toggle />
</Navbar.Header>
<Navbar.Collapse>
<Nav pullRight>
{isAuthenticated ? (
<>
<LinkContainer to="/settings">
<NavItem>Settings</NavItem>
</LinkContainer>
<NavItem onClick={handleLogout}>Logout</NavItem>
</>
) : (
<>
<LinkContainer to="/signup">
<NavItem>Signup</NavItem>
</LinkContainer>
<LinkContainer to="/login">
<NavItem>Login</NavItem>
</LinkContainer>
</>
)}
</Nav>
</Navbar.Collapse>
</Navbar>
<Routes appProps={{ isAuthenticated, userHasAuthenticated }} />
</div>
)
);
}
export default withRouter(App);
我做错了什么?
谢谢。