diff --git a/native/chat/compose-thread-button.react.js b/native/chat/compose-thread-button.react.js --- a/native/chat/compose-thread-button.react.js +++ b/native/chat/compose-thread-button.react.js @@ -11,45 +11,43 @@ import SWMansionIcon from '../components/swmansion-icon.react.js'; import { MessageListRouteName } from '../navigation/route-names.js'; import { useSelector } from '../redux/redux-utils.js'; -import { type Colors, useColors } from '../themes/colors.js'; +import { useColors } from '../themes/colors.js'; -type BaseProps = { - +navigate: $PropertyType, 'navigate'>, -}; type Props = { - ...BaseProps, - +colors: Colors, - +viewerID: ?string, + +navigate: $PropertyType, 'navigate'>, }; -class ComposeThreadButton extends React.PureComponent { - render() { - const { listForegroundSecondaryLabel } = this.props.colors; - return ( - - ); - } - - onPress = () => { - if (this.props.viewerID) { - this.props.navigate<'MessageList'>({ - name: MessageListRouteName, - params: { - threadInfo: createPendingThread({ - viewerID: this.props.viewerID, - threadType: threadTypes.PRIVATE, - }), - searching: true, - }, - }); +function ComposeThreadButton(props: Props) { + const { navigate } = props; + const viewerID = useSelector( + state => state.currentUserInfo && state.currentUserInfo.id, + ); + const onPress = React.useCallback(() => { + if (!viewerID) { + return; } - }; + navigate<'MessageList'>({ + name: MessageListRouteName, + params: { + threadInfo: createPendingThread({ + viewerID, + threadType: threadTypes.PRIVATE, + }), + searching: true, + }, + }); + }, [navigate, viewerID]); + + const { listForegroundSecondaryLabel } = useColors(); + return ( + + ); } const styles = StyleSheet.create({ @@ -58,17 +56,8 @@ }, }); -const ConnectedComposeThreadButton: React.ComponentType = React.memo( - function ConnectedComposeThreadButton(props) { - const colors = useColors(); - const viewerID = useSelector( - state => state.currentUserInfo && state.currentUserInfo.id, - ); - - return ( - - ); - }, +const MemoizedComposeThreadButton: React.ComponentType = React.memo( + ComposeThreadButton, ); -export default ConnectedComposeThreadButton; +export default MemoizedComposeThreadButton;