Skip to content

Commit e2cb45c

Browse files
committed
types(WidthProvider): fix HOC type in Flow
1 parent 02ff2b3 commit e2cb45c

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

lib/components/WidthProvider.jsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,26 @@ import PropTypes from "prop-types";
44
import ReactDOM from "react-dom";
55
import type { ComponentType as ReactComponentType } from "react";
66

7-
type Props = {
7+
type WPProps = {
88
className?: string,
99
measureBeforeMount: boolean,
1010
style?: Object
1111
};
1212

13-
type State = {
13+
type WPState = {
1414
width: number
1515
};
1616

1717
/*
1818
* A simple HOC that provides facility for listening to container resizes.
1919
*/
20-
type ProviderT = (
21-
ComposedComponent: ReactComponentType<any>
22-
) => ReactComponentType<any>;
23-
const WidthProvider: ProviderT = ComposedComponent =>
24-
class WidthProvider extends React.Component<Props, State> {
20+
export default function WidthProvider<
21+
Props,
22+
ComposedProps: { ...Props, ...WPProps }
23+
>(
24+
ComposedComponent: ReactComponentType<Props>
25+
): ReactComponentType<ComposedProps> {
26+
return class WidthProvider extends React.Component<ComposedProps, WPState> {
2527
static defaultProps = {
2628
measureBeforeMount: false
2729
};
@@ -32,7 +34,7 @@ const WidthProvider: ProviderT = ComposedComponent =>
3234
measureBeforeMount: PropTypes.bool
3335
};
3436

35-
state: State = {
37+
state = {
3638
width: 1280
3739
};
3840

@@ -62,14 +64,14 @@ const WidthProvider: ProviderT = ComposedComponent =>
6264
};
6365

6466
render() {
65-
if (this.props.measureBeforeMount && !this.mounted) {
67+
const { measureBeforeMount, ...rest } = this.props;
68+
if (measureBeforeMount && !this.mounted) {
6669
return (
6770
<div className={this.props.className} style={this.props.style} />
6871
);
6972
}
7073

71-
return <ComposedComponent {...this.props} {...this.state} />;
74+
return <ComposedComponent {...rest} {...this.state} />;
7275
}
7376
};
74-
75-
export default WidthProvider;
77+
}

0 commit comments

Comments
 (0)