我不知道为什么我收到以下错误“错误:元素类型无效:”

道格5索拉斯

我对 React 很陌生,甚至对 Firebase 也很陌生。我正在学习 Robin Wieruch 关于在 Firebase 中使用 React 的教程。显然,我做错了一些事情,但它让我望而却步。我正在使用一种使用文件夹命名我的组件的模式,每个组件文件夹中都有一个 index.js 文件来保存代码。

这是 App 组件的 index.js:

import React from 'react'
import { BrowserRouter as Router, Route } from 'react-router-dom'

import * as ROUTES from '../../constants/routes'

import Navigation from '../Navigation'
import LandingPage from '../Landing'
import SignUpPage from '../SignUp'
import SignInPage from '../SignIn'
import PasswordForgetPage from '../PasswordForget'
import HomePage from '../Home'
import AccountPage from '../Account'
import AdminPage from '../Admin'

const App = () => (
  <Router>
    <Navigation />

    <hr />

    <Route exact path={ROUTES.LANDING} component={LandingPage} />
    <Route path={ROUTES.SIGN_UP} component={SignUpPage} />
    <Route path={ROUTES.SIGN_IN} component={SignInPage} />
    <Route path={ROUTES.PASSWORD_FORGET} component={PasswordForgetPage} />
    <Route path={ROUTES.HOME} component={HomePage} />
    <Route path={ROUTES.ACCOUNT} component={AccountPage} />
    <Route path={ROUTES.ADMIN} component={AdminPage} />
  </Router>
)

export default App

这是 SignUp 组件的 index.js 文件

import React, { Component } from 'react'
import { Link, withRouter } from 'react-router-dom'
import { compose } from 'recompose'

import FirebaseContext, { withFirebase } from '../Firebase'
import * as ROUTES from '../../constants/routes'

const SignUpPage = () => (
  <div>
    <h1>SignUp</h1>
    <FirebaseContext.Consumer>
      { firebase => <SignUpForm firebase={firebase} />}
    </FirebaseContext.Consumer>
  </div>
)

...

export default SignUpPage

export { SignUpForm, SignUpLink }

我不确定任何其他文件是否会有所帮助。

我道歉。好像忘记了最重要的文件。这是来自 src 文件夹的 index.js:

import React from 'react'
import ReactDOM from 'react-dom'

import './index.css'
import * as serviceWorker from './serviceWorker'

import App from './components/App'
import Firebase, { FirebaseContext } from './components/Firebase'

ReactDOM.render(
    // make Firebase Context available to the app
    <FirebaseContext.Provider value={ new Firebase() }>
      <App />
    </FirebaseContext.Provider>, 
    document.getElementById('root'),
  )

错误出现在此文件 ReactDOM.render 的第 12 行。

根据@Victor 的请求,以下是 Firebase 组件:

来自 Firebase 文件夹的 index.js

import FirebaseContext, { withFirebase } from './context'
import Firebase from './firebase'

export default Firebase

export { FirebaseContext, withFirebase }

来自 Firebase 文件夹的 context.js

import React from 'react'

const FirebaseContext = React.createContext(null)

// create the HOC withFirebase
export const withFirebase = Component => props => (
  <FirebaseContext.Consumer>
    { firebase => <Component { ...props } firebase={ firebase } />}
  </FirebaseContext.Consumer>
)

export default FirebaseContext

Firebase 文件夹中的 firebase.js

import app from 'firebase/app'
import 'firebase/auth'
// import 'firebase/database'

// the constant value when the environment = 'production'
const prodConfig = {
  apiKey: process.env.REACT_APP_API_KEY,
  authDomain: process.env.REACT_APP_AUTH_DOMAIN,
  databaseURL: process.env.REACT_APP_DATABASE_URL,
  projectId: process.env.REACT_APP_PROJECT_ID,
  storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
  messagingSenderId: process.env.REACT_APP_SENDER_ID,
}

// the constant value when the environment !== 'production'
const devConfig = {
  apiKey: process.env.REACT_APP_API_KEY,
  authDomain: process.env.REACT_APP_AUTH_DOMAIN,
  databaseURL: process.env.REACT_APP_DATABASE_URL,
  projectId: process.env.REACT_APP_PROJECT_ID,
  storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
  messagingSenderId: process.env.REACT_APP_SENDER_ID,
}

// set the config constant to the appropriate value
const config = process.env.NODE_ENV === 'production' ? prodConfig : devConfig

class Firebase {
  constructor() {
    // initialize the app with the Firebase config
    app.initializeApp(config)

    this.auth = app.auth()
  }

  // ***** Auth API ***** (use the offical Firebase endpoint)
  doCreateUserWithEmailAndPassword = ( email, password ) => this.auth.createUserWithEmailAndPassword( email, password )

  // ***** SignIn ***** (use the offical Firebase endpoint)
  doSignInWithEmailAndPassword = ( email, password ) => this.auth.SignInWithEmailAndPassword( email, password )

  // ***** SignIn ***** (use the offical Firebase endpoint)
  doSignInWithEmailAndPassword = ( email, password ) => this.auth.SignInWithEmailAndPassword( email, password )

  // ***** SignOut ***** (use the offical Firebase endpoint)
  doSignOut = ( email, password ) => this.auth.SignOut()

  // ***** Password Reset ***** (use the offical Firebase endpoint)
  doPasswordReset = email => this.auth.sendPasswordResetEmail( email )

  // ***** Password Update ***** (use the offical Firebase endpoint)
  doPasswordUpdate = password => this.auth.currentUser.updatePassword( password )
}

export default Firebase

希望这样做。

道格5索拉斯

行!我想到了。问题是我试图在两个地方公开 FirebaseContext.Consumer,在 Firebase 文件夹中的 context.js 文件中(这是在这个应用程序中的位置)。但是我已经在 SignUp 文件夹中的 index.js 文件的 SignUpPage 块中留下了暴露 FirebaseContext.Consumer 的代码(这是我最初放置它的地方 - 在我构建 HOC(context.js)之前)。它(但没有真正看到它)一天半,我突然意识到我正在尝试双重任务。解决方案是如下重构 SignUpPage(与我上面的原始帖子相比):

注册组件的 index.js:

import React, { Component } from 'react'
import { Link, withRouter } from 'react-router-dom'
import { compose } from 'recompose'

import { withFirebase } from '../Firebase'
import * as ROUTES from '../../constants/routes'

const SignUpPage = () => (
  <div>
    <h1>SignUp Page</h1>
    <SignUpForm />
  </div>
)

...

const SignUpForm = compose(withRouter, withFirebase,)(SignUpFormBase)

export default SignUpPage

export { SignUpForm, SignUpLink }

感谢所有为我的思考过程做出贡献的人。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

不知道为什么我收到 StopIteration 错误

我收到这个 Intent 的错误,我不知道为什么

我不知道为什么我在 jsp 文件中收到这个简单代码的错误

Netsuite:我不知道为什么我的 query.load 收到此错误

我不断收到此错误消息,但我不知道为什么

我收到 mysqli 错误 1064 但我不知道为什么

我在 CSS 中不断收到此错误,但我不知道为什么

SMTP 错误,我不知道为什么

Dockerfile 错误的目录。我不知道为什么

不知道为什么我会收到此错误“SyntaxError: invalid token”?

我不知道为什么会收到“ Addressof”错误?

我不知道为什么python给我一个类型错误

反应类型错误,useState 不起作用。但我不知道为什么

我的陈述无效,我也不知道为什么

这是我的最终代码。我最终多次收到错误消息,但我不知道为什么

我在 Delphi 中收到“未声明的标识符”错误,我不知道为什么?

收到int错误,但我不知道为什么。我的文件没有多余的空格

我不知道为什么,但我收到错误:“AttributeError: 'super' 对象没有属性 '__getattr__'”

复制代码后,我在 Unity 中收到错误 Unexpected symbol 'void',我不知道为什么

语法无效,我不知道为什么

我不断得到细分错误:11错误,我不知道为什么... c ++

不知道为什么我在使用 Vue 时收到“错误 'Navbar' 已定义但从未使用过”

不知道为什么我会收到此错误:方法Illuminate \ View \ View :: paginate不存在?

我的代码给了我一个元组错误,我不知道为什么

不知道为什么我得到的错误会导致数组下标的错误类型为“ int [int]”

为什么我收到这个错误?似乎我在 s1.grade_level 中有错误,但我不知道为什么

我不知道为什么我的代码是错误的?那是什么错呢?

我不知道为什么我得到这个文件,但是仍然显示错误

我的min(list)函数产生错误的输出,我不知道为什么