0

I have two files in a tree that defines an object.

The common.js file.

export default {
  table: {
    actions: {
      save:   'Save',
      delete: 'Delete',
      update: 'Update'
    }
  }
};

In another file, I am calling the common.js file I just stated.

var common = require('common.js');

And whenever I access the object, as said, I get this;

console.log(common);
{
  common:{
    default: {
      table: {
        actions: {
          save: 'Save',
          delete: 'Delete',
          update: 'Update'
        }
      }
    }
  }
}

What I'm looking forward to get is the following;

{
  common: {
    table: {
      actions: {
        save:   'Save',
        delete: 'Delete',
        update: 'Update'
      }
    }
  }
}

That is without the default key. Is there a way I can export the table object and get it without the default key?

0

1 Answer 1

1

Just use import syntax instead of require syntax, and the value of the import will be the default export:

import common from 'common.js';
const obj = {
  common,
  // ...
}

https://codesandbox.io/s/5350980o54

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.