Created
December 2, 2020 15:02
-
-
Save imshuffling/12e11d7074fb3a5362124d0c3d5f6abb to your computer and use it in GitHub Desktop.
ContentModules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import PropTypes from 'prop-types' | |
import BlockTextLeft from './blocktextleft'; | |
import BlockTextArea from './blocktextarea'; | |
import BlockImage from './blockimage'; | |
import BlockTwoColumn from './blocktwocolumn'; | |
const MODULE_MAP = { | |
ContentfulTextLeft: BlockTextLeft, | |
ContentfulTextArea: BlockTextArea, | |
ContentfulImage: BlockImage, | |
ContentfulTwoColumn: BlockTwoColumn, | |
}; | |
const propTypes = { | |
blocks: PropTypes.any | |
}; | |
export default function ContentModules({blocks}) { | |
// console.log('---', blocks); | |
return ( | |
<> | |
{blocks.map(({"__typename": type, ...props}, i) => { | |
const Component = MODULE_MAP[type]; | |
return <Component key={i} {...props} />; | |
})} | |
</> | |
); | |
} | |
ContentModules.propTypes = propTypes; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment