Skip to content

Instantly share code, notes, and snippets.

@imshuffling
Created December 2, 2020 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imshuffling/12e11d7074fb3a5362124d0c3d5f6abb to your computer and use it in GitHub Desktop.
Save imshuffling/12e11d7074fb3a5362124d0c3d5f6abb to your computer and use it in GitHub Desktop.
ContentModules
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