简体   繁体   English

类型错误:_fire__WEBPACK_IMPORTED_MODULE_11__.default.collection 不是 function

[英]TypeError: _fire__WEBPACK_IMPORTED_MODULE_11__.default.collection is not a function

I have a project where I'm using Firebase for the backend and ReactJS as the front end.我有一个项目,我使用 Firebase 作为后端,使用 ReactJS 作为前端。 I have successfully implemented the authentication and it's up and running but I can't seem to make my Firestore work.我已经成功实现了身份验证,它已经启动并运行,但我似乎无法让我的 Firestore 工作。 here is my fire.js file:这是我的fire.js文件:

import firebase from 'firebase';
import "firebase/auth";
import "firebase/firestore";

if (!firebase.apps.length) {
    var fire = firebase.initializeApp({
   
      // my credentials //
    });
  
 }else {
   fire = firebase.app(); // if already initialized, use that one
 }
//const fire = firebase.initializeApp(firebaseConfig);
export default fire;

and here is the file in which I'm trying to add a contact document and then add name, email and message as fields:这是我尝试在其中添加联系人文档的文件,然后添加名称、email 和消息作为字段:

import { BrowserRouter as Router, Route, Link} from "react-router-dom";
//import AddRecord from './AddRecord';
import * as FaIcons from "react-icons/fa";
import * as AiIcons from "react-icons/ai";
import { SidebarData } from './SidebarData';
//import { AddRecord } from './components/AddRecord';
import { IconContext } from 'react-icons';
import Button from 'react-bootstrap/Button';

import fire from "../fire";


const ContactUs = () => {

    const [sidebar, setSidebar] = useState (false)

    const showSidebar = () => setSidebar(!sidebar)
    //const Hero handleLogout={handleLogout};

    const [name, setName] = useState("");
    const [email, setEmail] = useState("");
    const [message, setMessage] = useState("");

const handleSubmit = (e) => {
    e.preventDefault();

    fire.collection('contact').add({
        name: name,
        email: email,
        message: message,
    })
    .then(() => {
        alert("Thanks! We'll get back to you soon!");
    })
    .catch(error => {
        alert(error.message);
    })
    setName("");
    setEmail("");
    setMessage("");
};

    return (
        <div>
            <img src={croppped} className="mister" /> 
            <IconContext.Provider value ={{color: '3e9e91'}}>            
            <div className="navbar">
             <Link to ="#" className="menu-bars">   
                 <FaIcons.FaBars onClick={showSidebar} />
             </Link>  
            </div>
            <nav className={sidebar ? 'nav-menu active' : 'nav-menu'}>
                <ul className="nav-menu-items" onClick={showSidebar}>
                    <li className="navbar-toggle">
                        <Link to ="#" className="menu-bars">   
                        <AiIcons.AiOutlineClose/>
                        </Link>  
                    </li>
                    {SidebarData.map((item, index) => {
                        return (
                            <li key={index} className={item.cName}>
                                <Link to={item.path}>
                                    {item.icon}
                                    <span>{item.title}</span>
                                </Link>
                            </li>
                        )
                    })}
                </ul>
            </nav>
            </IconContext.Provider>
            
        <form className="form" onSubmit = {handleSubmit}>
            <h1>Stuck Somewhere? Contact Us!</h1>
             <input 
            placeholder="Enter Full Name"
            value={name}
            onChange={(e) => setName(e.target.value)} 
            />
                    
            <input placeholder="Enter Email"
            value={email}
            onChange={(e) => setEmail(e.target.value)} 
            />

            
            <textarea placeholder="Enter Message"
            value={message}
            onChange={(e) => setMessage(e.target.value)}>
            </textarea>

                    <button type="submit">Submit</button>
        </form>
        </div>
    )
}

export default ContactUs;

Your fire variable is the result of initializeApp , which is of type App.您的fire变量是initializeApp的结果,它是 App 类型。 You need to call the firestore method to access the Firestore Service Interface :您需要调用firestore方法来访问Firestore 服务接口

fire.firestore().collection('contact')...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 "类型错误:_fire__WEBPACK_IMPORTED_MODULE_1__.default.auth 不是函数" - TypeError: _fire__WEBPACK_IMPORTED_MODULE_1__.default.auth is not a function 类型错误:_firebase__WEBPACK_IMPORTED_MODULE_9__.default.collection 不是 function - TypeError: _firebase__WEBPACK_IMPORTED_MODULE_9__.default.collection is not a function 类型错误:_components_firebase__WEBPACK_IMPORTED_MODULE_3__.default.collection 不是函数 - TypeError: _components_firebase__WEBPACK_IMPORTED_MODULE_3__.default.collection is not a function 类型错误:_firebase__WEBPACK_IMPORTED_MODULE_2__.default.collection 不是函数 - TypeError: _firebase__WEBPACK_IMPORTED_MODULE_2__.default.collection is not a function TypeError:react__WEBPACK_IMPORTED_MODULE_6 ___ default.a.useState不是一个函数 - TypeError: react__WEBPACK_IMPORTED_MODULE_6___default.a.useState is not a function 类型错误:moment__WEBPACK_IMPORTED_MODULE_3___default(...)(...).calendar(...).sort 不是函数 - TypeError: moment__WEBPACK_IMPORTED_MODULE_3___default(...)(...).calendar(...).sort is not a function 类型错误:标记为__WEBPACK_IMPORTED_MODULE_3___default(...) 不是函数 - TypeError: marked__WEBPACK_IMPORTED_MODULE_3___default(...) is not a function 类型错误:_models_Products__WEBPACK_IMPORTED_MODULE_1__.default.find 不是函数 - TypeError: _models_Products__WEBPACK_IMPORTED_MODULE_1__.default.find is not a function 类型错误:firebase_app__WEBPACK_IMPORTED_MODULE_0___default.a.analytics 不是 function - TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_0___default.a.analytics is not a function 类型错误:Webpack 导入的模块不是 function - TypeError: Webpack imported module is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM