diff --git a/client/templates/sectionMap.tsx b/client/templates/sectionMap.tsx index facbd4792..039d6f0e2 100644 --- a/client/templates/sectionMap.tsx +++ b/client/templates/sectionMap.tsx @@ -44,11 +44,11 @@ const sectionMap = (Section: React.FC): Record, }); -export const getSectionById = (id: string, Section: React.FC): JSX.Element => { - // Check if section id is a custom section (an uuid) - if (validate(id)) { - return
; - } +export const getSectionById = (id: string, Section: React.FC): JSX.Element | null => { + if (!id) return null; + + // Check if section id is a custom section (is a valid uuid) + if (validate(id)) return
; // Check if section id is a predefined seciton in config const predefinedSection = get(sectionMap(Section), id); @@ -57,9 +57,11 @@ export const getSectionById = (id: string, Section: React.FC): JSX return predefinedSection; } - // Other ways section should be a cloned section - const section = find(sectionMap(Section), (element, key) => id.includes(key)); - return React.cloneElement(section!, { path: `sections.${id}` }); + // Otherwise, section must be a cloned section + const section = find(sectionMap(Section), (_element, key) => id.includes(key)); + if (section) return React.cloneElement(section, { path: `sections.${id}` }); + + return null; }; export default sectionMap;