首页 > 解决方案 > TypeError: Object (...) is not a function in react & js

问题描述

我有这段代码,但由于某种原因,它因错误而失败:

TypeError: Object(…) is not a function

它说它发生在第 70 行,就是这样:

export default withAuthentication(App)

这是我的这个页面的代码,它导入包,代码,然后在最后导出:

 import React from 'react'
import { Redirect, Route, Switch } from 'react-router-dom'
//import 'antd/dist/antd.css'
// (loading styles with with react-app-rewired / fixBabelImports / addLessLoader) to get overrides on colors and fonts

import * as routes from './routes'

import withAuthentication from './withAuthentication'
import AuthUserContext from './AuthUserContext'

import SignUpPage from './pages/SignUpPage'
import LoginPage from './pages/LoginPage'
import PasswordForgetPage from './pages/PasswordForgetPage'
import MainPage from './pages/MainPage'
import NewClientPage from './pages/NewClientPage'
import EditClientPage from './pages/EditClientPage'
import NewEstimatePage from './pages/NewEstimatePage'
import EditEstimatePage from './pages/EditEstimatePage'
import TestPage from './pages/TestPage'
import UserProfileContent from './components/UserProfileContent'
import StripeApp from './Stripepayment/StripeApp'
import NameRegistration from './components/NameField'
// import App from './App.js'

const App = ({ authUser }) => {
  return <AuthUserContext.Consumer>
    { authUser => authUser
      ? <LoggedInApp authUser={authUser}/>
      : <NotLoggedInApp />
    }
  </AuthUserContext.Consumer>
}



const NotLoggedInApp = () =>
  <Switch>
    <Route exact path={routes.SIGN_IN} component={LoginPage} />
    <Route exact path={routes.SIGN_UP} component={SignUpPage} />
    <Route exact path={routes.PASSWORD_FORGET} component={PasswordForgetPage} />
    <Route exact path={routes.NAMEREGISTER} component={NameRegistration} />
    <Route exact path={routes.STRIPEAPP} component={StripeApp} />
    <LoginPage />
  </Switch>

const TabRoute = ({ path }) =>
  <Route exact path={path} render={(props) => <MainPage showTab={path} {...props} />} />

const LoggedInApp = ({ authUser }) =>
  <Switch>
    <Route exact path={routes.SIGN_IN} component={LoginPage} />
    <Route exact path={routes.NEWCLIENT} component={NewClientPage} />
    <Route exact path={routes.EDITCLIENT + '/:id'} render={(props) => <EditClientPage clientId={props.match.params.id} />}/>
    <Route exact path={routes.NEWESTIMATE} component={NewEstimatePage} />
    <Route exact path={routes.EDITESTIMATE + '/:id'} render={(props) => <EditEstimatePage estimateId={props.match.params.id} />}/>
    <Route exact path={routes.TEST} component={TestPage} />
    <Route exact path={routes.PASSWORD_FORGET} component={PasswordForgetPage} />
    <Route exact path={routes.CLIENTS + '/:id'} render={(props) => <MainPage showTab={routes.CLIENTS} {...props} />} />
    <Route exact path={routes.ESTIMATES + '/:id'} render={(props) => <MainPage showTab={routes.ESTIMATES} {...props} />} />
    <Route exact path={routes.JOBS + '/:id'} render={(props) => <MainPage showTab={routes.JOBS} {...props} />} />
    
    
    <TabRoute path={routes.CLIENTS} />
    <TabRoute path={routes.ESTIMATES} />
    <TabRoute path={routes.JOBS} />
    <TabRoute exact path={routes.PROFILE} component={UserProfileContent}/>
    <Redirect to={routes.CLIENTS} />
  </Switch>


export default withAuthentication(App)

标签: javascriptnode.jsreactjsreact-redux

解决方案


推荐阅读