我遇到以下错误,如果有人可以将我指向正确的方向,那我会喜欢的:)
无法编译./src/App.js尝试导入错误:“ UserProvider” 不是从“ ./model/UserContext”导出的。
UserContext.js
const UserProvider = ({ children, history}) => { ... })
export default withRouter(UserProvider);
app.js
import React from 'react';
import NavBar from './components/navBar';
import Login from './components/login';
import Session from './components/session';
import Dashboard from './components/dashboard';
import './App.css';
import Container from '@material-ui/core/Container';
import {BrowserRouter as Router, Route, Switch} from 'react-router-dom';
import { UserProvider } from './model/UserContext'
function App() {
return (
<div>
<UserProvider>
<Session />
<NavBar />
<Container maxWidth="sm">
<Router>
<Route path='/Login' component={Login} />
<Route path='/Dashboard' component={Dashboard} />
</Router>
</Container>
</UserProvider>
</div>
);
}
export default App;
答案 0 :(得分:1)
您正在将UserProvider导出为默认值。因此,在App.js中,只需像下面那样导入(不带花括号)即可。
import UserProvider from './model/UserContext'
答案 1 :(得分:0)
import { UserProvider } from './model/UserContext'
您需要这样写:
import UserProvider from './model/UserContext'