简体   繁体   English

为什么 export default 在这个简单的代码中不起作用?

[英]Why export default doesn't work in this simple code?

Why when I use export default on index.js module it says: export 'appReducers' (imported as 'appReducers') was not found in './reducers/index' (possible exports: default), but when I change it to module.exports the error go away, why is that?为什么当我在 index.js 模块上使用 export default 时,它说: export 'appReducers' (imported as 'appReducers') is not found in './reducers/index' (可能的导出:默认),但是当我将其更改为模块时.exports 错误 go 消失,这是为什么呢?

At redux.js在 redux.js

import { appReducers } from './reducers/index'

const Store = () => {
  console.log(appReducers);
}

export default Store

in index.js在 index.js 中

const appReducers = "hello world";
export default appReducers

in app.js在 app.js 中

import React, { useState, useEffect, useMemo } from 'react';
import Store from './redux'

function App() {
  Store();
  return (
    <div>

    </div>
  );
}

export default App;

The problem is in redux.js .问题出在redux.js中。 Instead of代替

import { appReducers } from './reducers/index'

You need你需要

import appReducers from './reducers/index'

What you were doing before was a named import, not a default import.您之前所做的是命名导入,而不是默认导入。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM