Created
November 7, 2019 19:21
-
-
Save usulpro/bf3b67352993597fd0fcdb51c4c9e3f8 to your computer and use it in GitHub Desktop.
This file contains 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
// 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