Andrew Marin
Andrew Marin

Reputation: 1083

How to export ES6 class in Javascript without module.exports

I was converting older JS code to ES6 and had React Components in a separate file looking like this

export const SomeReactComponent = React.createClass({
    // Class methods
})
export const SomeReactComponent2 = React.createClass({
    // Class methods
})

that were imported from other files like this

import { SomeReactComponent, SomeReactComponent2 } from './file.js'

and I was wondering how to export those classes if using ES6 class notation. Note, that I don't want to use module.exports nor I want to use export default.

Upvotes: 0

Views: 422

Answers (1)

Andrew Marin
Andrew Marin

Reputation: 1083

The new syntax would look like this:

export class SomeReactComponent extends React.Component {
    // Class methods
}
export class SomeReactComponent2 extends React.Component {
    // Class methods
}

Upvotes: 2

Related Questions