From dbedbed8d56e02ad1bc358da25ca76de7c7fb7a8 Mon Sep 17 00:00:00 2001 From: Chris Beer <cabeer@stanford.edu> Date: Fri, 18 Sep 2020 08:11:20 -0700 Subject: [PATCH] Allow plugin components to be react elements --- __tests__/integration/mirador/plugins/add.html | 2 +- src/components/PluginHook.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/__tests__/integration/mirador/plugins/add.html b/__tests__/integration/mirador/plugins/add.html index fd3cd9631..d2dc92960 100644 --- a/__tests__/integration/mirador/plugins/add.html +++ b/__tests__/integration/mirador/plugins/add.html @@ -61,7 +61,7 @@ config: { foo: 'bar', }, - component: AddPluginComponentA, + component: <AddPluginComponentA />, }; const addPluginB = { diff --git a/src/components/PluginHook.js b/src/components/PluginHook.js index bdfcb325c..5c16c579c 100644 --- a/src/components/PluginHook.js +++ b/src/components/PluginHook.js @@ -6,11 +6,15 @@ export const PluginHook = React.forwardRef((props, ref) => { const { classes, ...otherProps } = props; // eslint-disable-line react/prop-types return PluginComponents ? ( PluginComponents.map((PluginComponent, index) => ( // eslint-disable-line react/prop-types - <PluginComponent - ref={ref} - {...otherProps} - key={index} // eslint-disable-line react/no-array-index-key - /> + React.isValidElement(PluginComponent) + ? React.cloneElement(PluginComponent, { ...otherProps, ref }) + : ( + <PluginComponent + ref={ref} + {...otherProps} + key={index} // eslint-disable-line react/no-array-index-key + /> + ) )) ) : null; }); -- GitLab