Skip to content

Commit

Permalink
feat: add dynamic component
Browse files Browse the repository at this point in the history
  • Loading branch information
Lisi Linhart committed May 11, 2021
1 parent 8a6542e commit cf90b8c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/components/dynamicComponent.js
@@ -0,0 +1,17 @@
import SbEditable from 'storyblok-react'
import Teaser from './Teaser'
import React from "react"

const Components = {
'teaser': Teaser,
}

const DynamicComponent = ({ blok }) => {
if (typeof Components[blok.component] !== 'undefined') {
const Component = Components[blok.component]
return (<SbEditable content={blok}><Component blok={blok} /></SbEditable>)
}
return (<p>The component <strong>{blok.component}</strong> has not been created yet.</p>)
}

export default DynamicComponent
14 changes: 14 additions & 0 deletions src/components/teaser.js
@@ -0,0 +1,14 @@
import * as React from "react"

const Teaser = ({ blok }) => (
<div>
<h2>
{ blok.headline }
</h2>
<p>
{ blok.intro }
</p>
</div>
)

export default Teaser

0 comments on commit cf90b8c

Please sign in to comment.