我陷入了要求我创建firebase/Context.jsx文件的步骤,该操作已完成,如下所示:

import React from 'react';

const FirebaseContext = React.createContext(null);

export default FirebaseContext;


然后在index.js中,我尝试将Firebase Context导入为:

import Firebase, { FirebaseContext } from './components/firebase/Context';


我收到一条错误消息:


  尝试导入错误:“ FirebaseContext”未从中导出
  './components/firebase/Context


我如何导出/导入反应?

最佳答案

要消除您发布的错误,请在firebase/Context.jsx中将其更改为:

import React from 'react';

export const FirebaseContext = React.createContext(null);


然后导入

import { FirebaseContext } from './components/firebase/Context';


或者,将firebase/Context.jsx文件保持不变(导出默认设置)并将导入更改为

import  FirebaseContext  from './components/firebase/Context';

09-19 23:36