最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Warning : Assign object to a variable before exporting as module default - Stack Overflow

programmeradmin3浏览0评论

I'm using react-redux, and this is my root Reducer:

import Customers from "./customers/reducer";

export default {
  Customers
};

but I got this warning: Assign object to a variable before exporting as module default. How do I deal with it?

I'm using react-redux, and this is my root Reducer:

import Customers from "./customers/reducer";

export default {
  Customers
};

but I got this warning: Assign object to a variable before exporting as module default. How do I deal with it?

Share Improve this question asked Nov 13, 2020 at 6:51 Steven Song Steven Song 711 gold badge1 silver badge3 bronze badges 4
  • Shouldn't this be export default Customers? – VLAZ Commented Nov 13, 2020 at 6:55
  • Right now, I just import one module, but later I will import more modules. While I tried your suggestion. That works. Thank you. –  Steven Song Commented Nov 13, 2020 at 7:06
  • If you want to re-export multiple things, then you likely want them as regular exports, not default ones. – VLAZ Commented Nov 13, 2020 at 7:09
  • @StevenSong If you import it only to export again (like an index.js collecting from othr files) you could do: export { default as Customers} from "./customers/reducer"; – HMR Commented Nov 13, 2020 at 8:37
Add a ment  | 

1 Answer 1

Reset to default 11

There are some solutions:

1- Disable the warning

import Customers from "./customers/reducer";

/* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */
export default {
    Customers
};

2- create a const then export it

import Customers from "./customers/reducer";
const aName = {
    Customers
};
export default aName;

Read this descriptions For more information.

发布评论

评论列表(0)

  1. 暂无评论