kharandziuk
kharandziuk

Reputation: 12910

export statement in js

There is a code sample in react's blog. Which looks like this:

export class Counter extends React.Component {
  constructor(props) {
    super(props);
    this.state = {count: props.initialCount};
  }
  tick() {
    this.setState({count: this.state.count + 1});
  }
  render() {
    return (
      <div onClick={this.tick.bind(this)}>
        Clicks: {this.state.count}
      </div>
    );
  }
}

What does the export statement mean in this case? I found this article on mdn but it describes another meaning

Upvotes: 1

Views: 398

Answers (1)

WayneC
WayneC

Reputation: 5740

It is used for ES6 modules

In that case it is exporting a class from that module, so you would be able to import it in another module using:

import { Counter } from 'path_to_counter';

You will need something like Webpack to do the module loading if you are using a browser, and possibly a transpiler like Babel.js for the ES6 transpilation

Upvotes: 3

Related Questions