[英]React - Uncaught TypeError: Class constructor Firebase cannot be invoked without 'new'
while using Firebase Auth in React I got this in the Console:在 React 中使用 Firebase Auth 时,我在控制台中得到了这个:
Uncaught TypeError: Class constructor Firebase cannot be invoked without 'new'
at Recompose.esm.js:803:1
at Module../src/components/globalPages/SignUp/index.js (index.js:113:1)
at Module.options.factory (react refresh:6:1)
at __webpack_require__ (bootstrap:24:1)
at fn (hot module replacement:61:1)
at Module../src/constants/routes.js (index.js:119:1)
at Module.options.factory (react refresh:6:1)
at __webpack_require__ (bootstrap:24:1)
at fn (hot module replacement:61:1)
at Module../src/components/App/index.js (bundle.js:15:75)
My code:我的代码:
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import reportWebVitals from './reportWebVitals';
import App from './components/App/index';
import Firebase, {
FirebaseContext
} from './components/Firebase';
ReactDOM.render( < React.StrictMode > < FirebaseContext.Provider value = {
new Firebase()
} > < App / > < /FirebaseContext.Provider> </React.StrictMode > , document.getElementById('root'));
reportWebVitals();
class Firebase {
constructor() {
firebase.initializeApp(FirebaseConfig);
}
createUserWithEmailAndPassword = (email, password) => firebase.auth().createUserWithEmailAndPassword(email, password);
signInWithEmailAndPassword = (email, password) => firebase.auth().signInWithEmailAndPassword(email, password);
signOut = () => firebase.auth().signOut();
passwordReset = email => firebase.auth().sendPasswordResetEmail(email);
passwordUpdate = password => firebase.auth().currentUser.updatePassword(password);
};
export default Firebase;
const provider = firebase.auth.GoogleAuthProvider();常量提供者 = firebase.auth.GoogleAuthProvider();
The above code was giving error, Uncaught TypeError: Class constructor Firebase cannot be invoked without 'new', In my case,上面的代码给出了错误,Uncaught TypeError: Class constructor Firebase cannot be invoked without 'new',在我的例子中,
so this is what I did所以这就是我所做的
const provider = new firebase.auth.GoogleAuthProvider();常量提供者 = 新 firebase.auth.GoogleAuthProvider();
just add "new" keyword.只需添加“新”关键字。 It worked for me, hope this helps
它对我有用,希望这有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.