31 lines
1,011 B
Markdown
31 lines
1,011 B
Markdown
---
|
|
title: "re-export javascript function"
|
|
date: 2021-10-05T08:45:34+02:00
|
|
draft: false
|
|
snippet_types:
|
|
- js
|
|
---
|
|
|
|
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
|
|
```ts
|
|
export { default as TrackingAction } from './actions';
|
|
export const track = (action: TrackingAction) =>
|
|
...
|
|
```
|
|
|
|
Then somewhere else:
|
|
src/client/components/GoButton/index.tsx
|
|
|
|
```ts
|
|
import {TrackingAction, track} from '../hooks/GATracking';
|
|
...
|
|
```
|
|
|
|
source: https://stackoverflow.com/questions/34576276/re-export-a-default-export
|