Import
does the same thing as require()
.
Import
is an ES6 syntax while require()
is common javascript.
See this post for more information.
Edit: you can safely use ES6 import/exports, i suggest you use only this syntax.
Usage with ES6 Import :
Export:
export class/const/func myFunc(){ dosmth };
Import :
Import { myFunc } from "./folder/file";
Export default :
export default myFunc;
Import :
Import myFunc from "./folder/file";
About best practice for React Native :
Prefer writing one component per file, export it by default.
Generally, if you have 1 export in a file do a default export.
If you have more do normal exports.
Always do all your imports at top of the file, from dependencies first then you local imports.