Skip to content

Commit a5dedf7

Browse files
committed
fix: Stateless function components cannot be given refs
1 parent 1045577 commit a5dedf7

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed

src/makeAsync.js

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,36 @@ export default (opts = {}) => (Comp) => {
1919
reloadOnUpdate = false,
2020
reloadDependents = null,
2121
} = opts;
22-
const C = (props) => {
23-
const { wrappedComponentRef, ...remainingProps } = props;
24-
const wrapperProps = {
25-
batch,
26-
asyncJobs,
27-
asyncProps,
28-
asyncPropOpts,
29-
asyncPropsMapper,
30-
errorComponent,
31-
loadingComponent,
32-
onError,
33-
delay,
34-
unwrapDefault,
35-
reloadOnUpdate,
36-
reloadDependents,
37-
syncProps: {
38-
...remainingProps,
39-
ref: wrappedComponentRef,
40-
},
41-
};
42-
if (isPromise(Comp)) {
43-
wrapperProps.asyncComponent = () => Comp;
44-
} else {
45-
wrapperProps.component = Comp;
22+
// eslint-disable-next-line
23+
class C extends React.Component {
24+
render() {
25+
const { wrappedComponentRef, ...remainingProps } = this.props;
26+
const wrapperProps = {
27+
batch,
28+
asyncJobs,
29+
asyncProps,
30+
asyncPropOpts,
31+
asyncPropsMapper,
32+
errorComponent,
33+
loadingComponent,
34+
onError,
35+
delay,
36+
unwrapDefault,
37+
reloadOnUpdate,
38+
reloadDependents,
39+
syncProps: {
40+
...remainingProps,
41+
ref: wrappedComponentRef,
42+
},
43+
};
44+
if (isPromise(Comp)) {
45+
wrapperProps.asyncComponent = () => Comp;
46+
} else {
47+
wrapperProps.component = Comp;
48+
}
49+
return <AsyncComponent {...wrapperProps} />;
4650
}
47-
return <AsyncComponent {...wrapperProps} />;
48-
};
51+
}
4952
C.displayName = `makeAsync(${!isPromise(Comp) ? (Comp.displayName || Comp.name) : 'Unknown'})`;
5053
C.propTypes = {
5154
// eslint-disable-next-line

0 commit comments

Comments
 (0)