# Dynamic import

**URL:** <https://talk.observablehq.com/t/dynamic-import/6896>\
**Category:** Help\
**Created:** [August 2, 2022, 6:24pm UTC](https://talk.observablehq.com/t/dynamic-import/6896 "2022-08-02T18:24:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stevenweaver](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/stevenweaver/32/6821_2.png) [@stevenweaver](https://talk.observablehq.com/u/stevenweaver)\
**Post date:** [August 2, 2022, 6:24pm UTC](https://talk.observablehq.com/t/dynamic-import/6896/1 "2022-08-02T18:24:07Z")

</div>

Hi all,

First off, I would like to thank you for ObservableHQ, it has been a great resource over the past 4 years, and the engineering behind it is remarkable.

I’m at a bit of loss with an issue I have at the moment.

I have a piece of code that looks like so.

```auto
import {exportCSVData as exportCSVData1} 
with {h1 as galaxyHistoryId}
from "@stevenweaver/ngsqc-parser"

```

`h1` is currently an ID that is passed into another notebook. What I would like is iterate over a list of IDs, and assign an array of resulting export variables.

For example

```auto
import {exportCSVData as exportCSVData2} 
with {h2 as galaxyHistoryId}
from "@stevenweaver/ngsqc-parser"

import {exportCSVData as exportCSVData3} 
with {h3 as galaxyHistoryId}
from "@stevenweaver/ngsqc-parser"

```

and so on, but programmatically. Is there any way to make this possible?

Best and thank you,  
Steven

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [August 2, 2022, 8:19pm UTC](https://talk.observablehq.com/t/dynamic-import/6896/2 "2022-08-02T20:19:28Z")

</div>

Thanks Steven!

Yes, it’s possible to do dynamic imports (see [this prototype](https://observablehq.com/@mbostock/dataflow)) but I don’t think I recommend it as it’s not really a supported feature. Instead I recommend refactoring the notebook you import as a function and avoiding import-with entirely. So you might say something like this:

```nohighlight
import {exportCSVData} from "@stevenweaver/ngsqc-parser"

```

```nohighlight
exportCSVData({galaxyHistoryId: h2})

```

```nohighlight
exportCSVData({galaxyHistoryId: h3})

```

You’ll have to rewrite your other notebook to be more function-based rather than cell-based, but overall it’ll make it easier to reuse in the standard JavaScript way.

---

<div class="post-metadata">

**Author:** ![stevenweaver](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/stevenweaver/32/6821_2.png) [@stevenweaver](https://talk.observablehq.com/u/stevenweaver)\
**Post date:** [August 2, 2022, 8:46pm UTC](https://talk.observablehq.com/t/dynamic-import/6896/3 "2022-08-02T20:46:37Z")

</div>

Thank you mbostock.

I was leaning towards that way, but I just wanted to make sure.

Best,  
Steven
