'es2015 modules - how to name exports dynamically
I would like to create a module, h, which exports one function for every HTML element. Here's how it might be used:
import {div, p} from 'h'
const myDiv = div(p('some text'))
Here's how that module is defined:
const h = {}
for (let tagName of ['div', 'p', /* ... */]) {
h[tagName] = (...children) => {
// ...
}
}
export const div = h.div
export const p = h.p
/* ... */
I don't like that every export has to be listed explictly. How do I make these dynamic?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
