I know there are two kinds of exports, one is named default and other is the default export.
// utils.js
const addOne = (a) => a+1;
export default addOne;
export const subOne = (a) => a- 1;
//app.js
import plusOne, {subOne} from './utils.js'
I am so confused about why we need a default export, it just can use only once. The only reason is the named export provide the name locally, and the default export can rename. However, if we have namely demand, maybe we need to use it repeatedly.
The default import isn't required. You can use named exports all you want. In your case, when you're exporting a bunch of utility functions, it would likely be better to use named exports. However, if you need to export just one function, usually a class, a default export is ideal.
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