re-export javascript function - 10-05-21

When splitting logic into files in JavaScript it sometimes happens you have a folder of files; say for a single domain like Google analytics tracking. There comes a time in another part of the code where you need to import some functions and types from this GATracking folder but you may not want to dig into which file in the folder that function is. Re-exporting allows us to keep the API of the GATracking logic consise and allow the rest of the program to not worry about how exactly the files are structured. Example:

src/client/hooks/GATracking/index.tsx

export { default as TrackingAction } from './actions';
export const track = (action: TrackingAction) =>
...

Then somewhere else: src/client/components/GoButton/index.tsx

import {TrackingAction, track} from '../hooks/GATracking';
...

source: https://stackoverflow.com/questions/34576276/re-export-a-default-export

\- [ js ]