Skip to content

Commit b67fefa

Browse files
authored
ref(ui) Update withSdkUpdates HOC off of createReactClass (#26601)
1 parent 40a7983 commit b67fefa

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

static/app/utils/withSdkUpdates.tsx

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import * as React from 'react';
2-
import createReactClass from 'create-react-class';
3-
import Reflux from 'reflux';
42

53
import {loadSdkUpdates} from 'app/actionCreators/sdkUpdates';
64
import {Client} from 'app/api';
@@ -29,21 +27,17 @@ type Props = {
2927
};
3028

3129
type State = {
32-
sdkUpdates: ProjectSdkUpdates[];
30+
sdkUpdates: ProjectSdkUpdates[] | null;
3331
};
3432

3533
function withSdkUpdates<P extends InjectedProps>(
3634
WrappedComponent: React.ComponentType<P>
3735
) {
38-
const ProjectSdkSuggestions = createReactClass<
39-
Props & Omit<P, keyof InjectedProps>,
36+
class WithProjectSdkSuggestions extends React.Component<
37+
Omit<P, keyof InjectedProps> & Props,
4038
State
41-
>({
42-
mixins: [Reflux.listenTo(SdkUpdatesStore, 'onSdkUpdatesUpdate') as any],
43-
44-
getInitialState() {
45-
return {sdkUpdates: []};
46-
},
39+
> {
40+
state: State = {sdkUpdates: []};
4741

4842
componentDidMount() {
4943
const orgSlug = this.props.organization.slug;
@@ -56,21 +50,32 @@ function withSdkUpdates<P extends InjectedProps>(
5650
}
5751

5852
loadSdkUpdates(this.props.api, orgSlug);
59-
},
53+
}
54+
55+
componentWillUnmount() {
56+
this.unsubscribe();
57+
}
58+
unsubscribe = SdkUpdatesStore.listen(() => this.onSdkUpdatesUpdate(), undefined);
6059

6160
onSdkUpdatesUpdate() {
6261
const sdkUpdates = SdkUpdatesStore.getUpdates(this.props.organization.slug) ?? null;
6362
this.setState({sdkUpdates});
64-
},
63+
}
6564

6665
render() {
66+
// TODO(ts) This unknown cast isn't great but Typescript complains about arbitrary
67+
// types being possible. I think this is related to the additional HoC wrappers causing type data to
68+
// be lost.
6769
return (
68-
<WrappedComponent {...(this.props as P)} sdkUpdates={this.state.sdkUpdates} />
70+
<WrappedComponent
71+
{...((this.props as unknown) as P)}
72+
sdkUpdates={this.state.sdkUpdates}
73+
/>
6974
);
70-
},
71-
});
75+
}
76+
}
7277

73-
return withOrganization(withApi(ProjectSdkSuggestions));
78+
return withOrganization(withApi(WithProjectSdkSuggestions));
7479
}
7580

7681
export default withSdkUpdates;

0 commit comments

Comments
 (0)