File: SafeString.js
// Build out our basic SafeString type function SafeString(string) { this.string = string; } SafeString.prototype.toString = function() { return "" + this.string; }; export default SafeString;
I have never seen export default
before. Are there any equivalent stuff for export default
that can be easier to understand?
export default is used to export a single class, function or primitive from a script file. The export can also be written as export default class HelloWorld extends React.Component { render() { return <p>Hello, world!</
Exports without a default tag are Named exports. Exports with the default tag are Default exports. Using one over the other can have effects on your code readability, file structure, and component organization. Named and Default exports are not React-centric ideas.
The export declaration is used when creating JavaScript modules to export live bindings to functions, objects, or primitive values from the module so they can be used by other programs with the import declaration. The value of an imported binding is subject to change in the module that exports it.
Default exports enable developers to export only a single class, function, variable, object, array, constant, etc. You write module. exports and assign a component that you want to export as default exports. Note: If you are interested in learning what is named exports in Node. js, then visit Node.
It's part of the ES6 module system, described here. There is a helpful example in that documentation, also:
If a module defines a default export:
// foo.js export default function() { console.log("hello!") }
then you can import that default export by omitting the curly braces:
import foo from "foo"; foo(); // hello!
Update: As of June 2015, the module system is defined in §15.2 and the export
syntax in particular is defined in §15.2.3 of the ECMAScript 2015 specification.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With