Skip to content

Load dynamic node modules #27

@janosh

Description

@janosh

Is it possible to load node modules asynchronously using async-reactor. The following snippet does not work but I hope explains the use case:

import React from 'react'
import { asyncReactor } from 'async-reactor'

const Component = async arr => (
  <div>
    {arr.map(obj => {
      const Icon = await import(obj.nodeModule)
      return (
        <div key={obj.title}>
          <Icon /> {obj.title}
        </div>
      )
    })}
  </div>
)

export default asyncReactor(Component)

obj.nodeModule is a dynamic string and the import path of a node module, in my case styled-icons, e.g. obj.nodeModule = styled-icons/boxicons-logos/Github.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions