From 035c00ee099714a7d9cd911d68fc08b1507a88ac Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 15 Jun 2017 01:28:06 +0700 Subject: [PATCH] Only create Slot elements once, support Class Components as defaultComponent --- client/coral-framework/components/Slot.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/client/coral-framework/components/Slot.js b/client/coral-framework/components/Slot.js index d313193e3..ca246591b 100644 --- a/client/coral-framework/components/Slot.js +++ b/client/coral-framework/components/Slot.js @@ -4,10 +4,15 @@ import styles from './Slot.css'; import {connect} from 'react-redux'; import {getSlotElements} from 'coral-framework/helpers/plugins'; -function Slot ({fill, inline = false, className, plugin_config: config, defaultComponent = () => {}, ...rest}) { +function Slot ({fill, inline = false, className, plugin_config: config, defaultComponent: DefaultComponent, ...rest}) { + let children = getSlotElements(fill, {...rest, config}); + if (children.length === 0 && DefaultComponent) { + children = ; + } + return (
- {getSlotElements(fill).length ? getSlotElements(fill, {...rest, config}) : defaultComponent({...rest})} + {children}
); }