DisplayComponentArray

Use DisplayComponentArray when you want to render a component multiple times, each time with different value for a given prop.

First import the components you need.

markdown
import { Button } from "@smerth/gatsby-theme-theme-ui"

Nota Bene

DisplayComponentArray is in scope for mdx documents and so there is no need to import it.

Next export the component you want to display. You can wrap up any amount of complexity you want in this function as long as it is exported.

markdown
export function ButtonsBySize(props) {
return <Button {...props}>{props.size} Button</Button>
}

Lastly pass the component and an array of prop values into the DisplayComponentArray component

markdown
<DisplayComponentArray
component={ButtonsBySize}
propsArray={{ size: ["sm", "md", "lg"] }}
/>

Which renders an array of the component with different values for the specified prop.

size="sm"

size="md"

size="lg"

© 2023 - smerth.com - All Rights Reserved