can I export more than one function per file ? it seems like when I do that , the second function ovverides the first one ,
example :
in my index.js
file
there are couple of ways to export and import objects/functions
export function first() {}
export function second() {}
in other file
import { first, second} from './somepath/somefile/';
if you want to use default, in general if there is only one export in a file it should be a default export. but if you for some reasons want two functions as default then you have to club them as a object and export that object as default
function first() {}
function second() {}
const funcs= {"first":first,"second":second}
export default funcs;
in other file
import funcs from './somepath/somefile/';
funcs.first();funs.second();
this should be it.
madox2's answer totally works if you want to import named functions.
If you still want to import the default, there's another technique:
function a() {}
function b() {}
export default { a, b }
and when you import:
import myObject from './index.js';
myObject.a(); // function a
myObject.b(); // function b
I hope this helps!
You can use named export instead of default:
export function aFnt(){
console.log("function a");
}
export function bFnt(){
console.log("function b");
}
and import it like:
import {aFnt, bFnt} from "./index";