Components Can .render()
Other Components
class OMG extends React.Component {
render() {
return <h1>Whooaa!</h1>;
}
}
class Crazy extends React.Component {
render() {
return <OMG />;
}
}
import
ing Variables from External Files
import { varName } from './filePath.js';
export
You also need an export
statement in the other file that contains the variable you're importing.
export
comes from ES6's module system, like import
does.
Named export
// Manifestos.js:
export const faveManifestos = {
futurist: 'http://bit.ly/1lKuB2I',
SCUM: 'http://bit.ly/1xWjvYc',
cyborg: 'http://bit.ly/16sbeoI'
};
export const alsoRan = 'TimeCube';
You can export
multiple things from the same file.
In a different file, import
the name of the var
, let
, const
, function
or class
name from the first file.
// App.js:
// Import faveManifestos and alsoRan from ./Manifestos.js:
import { faveManifestos, alsoRan } from './Manifestos';
// Use faveManifestos:
console.log(`A Cyborg Manifesto: ${faveManifestos.cyborg}`);