Replies: 2 comments 3 replies
-
Sure! It would help if you could elaborate on what you've tried so far, and where you got blocked by lack of information. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hey! I created a component acting as a "component switcher". It takes an object with the data as a prop. Based on a "name" property, it dynamically imports the right component. Works perfectly (see example below). The only thing I noticed (I feel it's expected) is that the scoped styles from imported components are no longer applied. Only ---
import dynamic from "astro:import"
let componentName = ''
const { item } = Astro.props
function setComponent(component) {
switch (component) {
case 'bock_richText':
componentName = 'BlockRichText'
break;
case 'block_card':
componentName = 'BlockCard'
break;
default: 'BlockRichText'
break;
}
}
setComponent(item.name)
const toImport = `components/${componentName}.astro`
const Component = await dynamic(toImport)
---
<Component content={item}> |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I'm trying to use astro-dynamic-import but I don't understand the example provided.
I have made a "builder" inside a CMS (directus) and I'm trying to import the right component for the right block in astro. Your integration seems ideal but I'm stuck with implementation.
Could you prrovide a more detailed example please?
Thanks a lot!
Beta Was this translation helpful? Give feedback.
All reactions