Skip to content

Instantly share code, notes, and snippets.

@usulpro
Created November 7, 2019 19:21
Show Gist options
  • Save usulpro/bf3b67352993597fd0fcdb51c4c9e3f8 to your computer and use it in GitHub Desktop.
Save usulpro/bf3b67352993597fd0fcdb51c4c9e3f8 to your computer and use it in GitHub Desktop.
// lib/renderNestedComponents.js
import React from "react";
import { componentsMap } from "./componentsMap";
import {
selectComponentReference,
selectComponentProps,
selectEntryId,
} from "./cms-selectors";
export const renderComponents = (content, options) => {
if (!content) return null;
return content.map((component, ind) => {
const reference = selectComponentReference(component);
const Component = componentsMap[reference];
const id = selectEntryId(component);
const props = selectComponentProps(component);
const updatedOptions = { ...options, renderComponents };
return (
<Component key={`${id}-${ind}`} {...props} options={updatedOptions} />
);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment