using newest react api to forward a dom ref

This commit is contained in:
NikolaBorislavovHristov 2018-06-21 16:24:14 +03:00
parent e7982594cd
commit 201fff78ec
2 changed files with 4 additions and 4 deletions

View file

@ -1,7 +1,7 @@
import React from 'react';
const Label = ({ children, forwardedRef, onClick }) => {
return React.cloneElement(React.Children.only(children), { ref: forwardedRef, onClick });
};
const Label = React.forwardRef(({ children, onClick }, ref) => {
return React.cloneElement(React.Children.only(children), { ref, onClick });
});
export default Label;

View file

@ -127,7 +127,7 @@ class Popup extends PureComponent {
return (
<Fragment>
{React.Children.map(this.props.children, (child) => {
return child.type === Label ? React.cloneElement(child, { forwardedRef: this.labelRef, onClick: this.open }) : null;
return child.type === Label ? React.cloneElement(child, { ref: this.labelRef, onClick: this.open }) : null;
})}
{this.renderMenu()}
</Fragment>