React Native Extended Multiple Components vs createClass

I saw a lot of tutorials with code that suggests doing something like the following:

var App = React.createClass({
    someFunction() { .. },
    render() { return(); },
});
var Lication = React.createClass({
    someOtherFunction() { .. },
    render() { return(); },
});

... but I used the ES6 syntax:

class App extends Component {
    someFunction() { .. }
    render { return(); }
}

Where can I create a class Lication? Right under the App class? Or you need its own file and is imported into the main file with something like:

var Lication = require('./Lication');

I still need to see code that uses several classes.

+4
source share
1 answer

Where can I create a Lication class? Right under the App class? Or does he need his own file?

ES6 React createClass , . . ES6 : hoisting:

, , - . , .

, - :

var l = new Lication(); // ReferenceError

class Lication {}

, :

class App extends React.Component {
  // ...
}

class Lication extends React.Component {
  // ...
}

:

class App extends React.Component {
  // ...
}

var Lication = require('path-to-lication-class');

Lication :

class Lication extends React.Component {
  // ...
}

module.exports = Lication;

:

class App extends React.Component {
  // ...
}

var Lication = class Lication extends React.Component {
  // ...
}

, ( ), , , .

+5

All Articles