Export more than one variable in ES6?

In order to export multiple variables we have to take everything we want to export from a file inside { } like this -

export { <var 1>, <var 2> , <var 3>, ... , <var n>};

for default export we can separately write this-

export default <var name>;  // there can be only one deafault export; 

In you code you can make the following changes -

exports.js

export { Post };

main.js

import { Post } from '<exports file>';

example


You can export multiple objects like this in ES6

var TestObject = Parse.Object.extend('TestObject')
var Post = Parse.Object.extend('Post')

export {
    TestObject,
    Post
}

Then, when importing you do it like this:

import { TestObject, Post } from './your-file';

You can read all about import and export here.


That is not valid syntax. You can do

export { Post }

or even just

export var Post = Parse.Object.extend('Post')

or shorten the whole file to

export default Parse.Object.extend('TestObject')
export var Post = Parse.Object.extend('Post')

Your imports are also incorrect, you'll want to do

import TestObject, { Post } from '../store'

This is if you really want a single default export and a separate named export. You can also just make two named exports and have no default if you want, e.g.

export var TestObject = Parse.Object.extend('TestObject');
export var Post = Parse.Object.extend('Post');

or

var TestObject = Parse.Object.extend('TestObject');
var Post = Parse.Object.extend('Post');
export { TestObject, Post };

and import with

import { TestObject, Post } from '../store'