user9076140
user9076140

Reputation: 11

Dummy database, Exporting more than one default

So, guys, I am trying to create a dummy database that for a project I am working on, now I will take a Todo app as an example.

    const todos =  [
      {
        id: 1,
        title: "lunch",
        description: "Go for lunc by 2pm"
      }
      ];

     export default todos;

this is quite alright! but when I create let's say a Todo list and a list of items to be bought from a store-

     const todos =  [
       {
        id: 1,
        title: "lunch",
        description: "Go for lunc by 2pm"
        }

     const shoppingList =  [
         {
         id: 1,
         item: "lunch",
         description: "Go for lunc by 2pm"
         }
          ];

export default todos; export default shoppingList;

if I try to run this I get this error message "Only one default export allowed per module. (90:0- which is the last line from what I have given above )"

Upvotes: 1

Views: 73

Answers (2)

user7457499
user7457499

Reputation: 11

You are using two exports with default either use only single export with default passing all components inside like:

export default {todos, shoppingList};

As only one export default is allowed.

Or you can put both components into one root component and export it.

If you still plan to use two different export statements just remove default keyword from it. Hope that helps.

You can also refer here for more detailed understanding: exporting modules

Upvotes: 1

Pranay
Pranay

Reputation: 430

module.exports = {
    todos: function() {return todos},
    shoppingList : function {return shoppingList }
}

Upvotes: 1

Related Questions