add the old snippet md files
This commit is contained in:
parent
fc0dd204c7
commit
bcf8313a4b
110 changed files with 3048 additions and 0 deletions
31
old_snippets/re-export-js-fn.en.md
Normal file
31
old_snippets/re-export-js-fn.en.md
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue