From 2b393959d96fca6396c4cf4869f4b258be1631b7 Mon Sep 17 00:00:00 2001 From: Qiming Weng Date: Thu, 2 Jul 2015 15:50:31 -0400 Subject: [PATCH] Fix displayName Fix displayName and add the top and left properties in addition to topOffset and leftOffset --- src/index.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/index.js b/src/index.js index b08877f..2826762 100644 --- a/src/index.js +++ b/src/index.js @@ -3,20 +3,22 @@ import {debounce} from 'lodash'; /** * This is a higher order component decorator - * - * It listens for when its children are mounted, then it measures the size of + * + * It listens for when its children are mounted, then it measures the size of * these children on the dom. Then it updates the children with appropriate * top and left offsets. - * + * * Components that are wrapped with this decorator recieve two properties * topOffset and leftOffset, they are null before the component has mounted. * * When the window is resized, this component will reupdate its children. This process * is debounced by 100ms to reduce CPU strain */ -export default function centerComponent(ReactClass) { +export default function centerComponent(DecoratedComponent) { + const componentClassName = DecoratedComponent.displayName || DecoratedComponent.name || 'Component'; + return class Centered extends React.Component { - static displayName = ReactClass.displayName + 'Centered' + static displayName = componentClassName + 'Centered' state = { topOffset: null, leftOffset: null @@ -57,13 +59,15 @@ export default function centerComponent(ReactClass) { const {topOffset, leftOffset} = this.state; return ( - + ) } } -} \ No newline at end of file +}