Skip to content

Commit dfaec2e

Browse files
committed
MentionWarnings [nfc]: Use useSelector instead of connect.
An instance of zulip#4837. See the previous commit for more details, and see zulip#4942 (comment) for why we do React.createRef<React$ElementRef<typeof MentionWarnings>>() instead of putting something else for createRef's type parameter.
1 parent 988cdd7 commit dfaec2e

File tree

2 files changed

+8
-33
lines changed

2 files changed

+8
-33
lines changed

src/compose/ComposeBox.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,7 @@ class ComposeBox extends PureComponent<Props, State> {
138138
messageInputRef = React.createRef<$FlowFixMe>();
139139
topicInputRef = React.createRef<$FlowFixMe>();
140140

141-
// TODO: Type-check this, once we've adjusted our `react-redux`
142-
// wrapper to do the right thing. It should be
143-
//
144-
// mentionWarnings = React.createRef<React$ElementRef<MentionWarnings>>()
145-
//
146-
// but we need our `react-redux` wrapper to be aware of
147-
// `{ forwardRef: true }`, since we use that.
148-
mentionWarnings = React.createRef();
141+
mentionWarnings = React.createRef<React$ElementRef<typeof MentionWarnings>>();
149142

150143
inputBlurTimeoutId: ?TimeoutID = null;
151144

@@ -503,10 +496,6 @@ class ComposeBox extends PureComponent<Props, State> {
503496

504497
return (
505498
<View style={this.styles.wrapper}>
506-
{/*
507-
$FlowFixMe[incompatible-use]:
508-
`MentionWarnings` should use a type-checked `connect`
509-
*/}
510499
<MentionWarnings narrow={narrow} stream={stream} ref={this.mentionWarnings} />
511500
<View style={[this.styles.autocompleteWrapper, { marginBottom: height }]}>
512501
<TopicAutocomplete

src/compose/MentionWarnings.js

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/* @flow strict-local */
22

3-
import { connect } from 'react-redux';
43
import React, { useState, useCallback, useContext, forwardRef, useImperativeHandle } from 'react';
4+
import { useSelector } from 'react-redux';
55

6-
import type { Auth, Stream, Dispatch, Narrow, UserOrBot, Subscription, UserId } from '../types';
6+
import type { Stream, Narrow, UserOrBot, Subscription, UserId } from '../types';
77
import { TranslationContext } from '../boot/TranslationProvider';
88
import { getAllUsersById, getAuth } from '../selectors';
99
import { is1to1PmNarrow } from '../utils/narrow';
@@ -13,17 +13,9 @@ import { showToast } from '../utils/info';
1313
import MentionedUserNotSubscribed from '../message/MentionedUserNotSubscribed';
1414
import { makeUserId } from '../api/idTypes';
1515

16-
type SelectorProps = {|
17-
auth: Auth,
18-
allUsersById: Map<UserId, UserOrBot>,
19-
|};
20-
2116
type Props = $ReadOnly<{|
2217
narrow: Narrow,
2318
stream: Subscription | {| ...Stream, in_home_view: boolean |},
24-
25-
dispatch: Dispatch,
26-
...SelectorProps,
2719
|}>;
2820

2921
type ImperativeHandle = {|
@@ -32,7 +24,10 @@ type ImperativeHandle = {|
3224
|};
3325

3426
function MentionWarnings(props: Props, ref) {
35-
const { stream, narrow, auth, allUsersById } = props;
27+
const { stream, narrow } = props;
28+
29+
const auth = useSelector(getAuth);
30+
const allUsersById = useSelector(getAllUsersById);
3631

3732
const [unsubscribedMentions, setUnsubscribedMentions] = useState<UserId[]>([]);
3833

@@ -169,13 +164,4 @@ function MentionWarnings(props: Props, ref) {
169164
return mentionWarnings;
170165
}
171166

172-
// $FlowFixMe[missing-annot]. TODO: Use a type checked connect call.
173-
export default connect(
174-
state => ({
175-
auth: getAuth(state),
176-
allUsersById: getAllUsersById(state),
177-
}),
178-
null,
179-
null,
180-
{ forwardRef: true },
181-
)(forwardRef<Props, ImperativeHandle>(MentionWarnings));
167+
export default forwardRef<Props, ImperativeHandle>(MentionWarnings);

0 commit comments

Comments
 (0)