From 2136302d528aceee6f698005b14bb151e8b47baf Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 6 Sep 2024 15:43:03 +0200 Subject: [PATCH] =?UTF-8?q?[Refactoring]=20`usePrevious2=20=E2=86=92=20use?= =?UTF-8?q?Previous`,=20`usePrevious=20=E2=86=92=20usePreviousDeprecated`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/App.tsx | 4 ++-- .../calls/group/MicrophoneButton.tsx | 4 ++-- .../calls/group/OutlinedMicrophoneIcon.tsx | 6 ++--- .../group/hooks/useGroupCallVideoLayout.ts | 6 ++--- src/components/common/AnimatedCounter.tsx | 4 ++-- src/components/common/CalendarModal.tsx | 4 ++-- src/components/common/Composer.tsx | 4 ++-- src/components/common/CountryPickerModal.tsx | 4 ++-- .../common/CustomEmojiSetsModal.tsx | 4 ++-- src/components/common/DeleteMessageModal.tsx | 4 ++-- src/components/common/ManageUsernames.tsx | 4 ++-- src/components/common/ProfileInfo.tsx | 6 ++--- src/components/common/StickerSetModal.tsx | 4 ++-- src/components/common/UsernameInput.tsx | 4 ++-- src/components/left/LeftColumn.tsx | 4 ++-- src/components/left/main/ForumPanel.tsx | 4 ++-- .../useLeftHeaderButtonRtlForumTransition.ts | 4 ++-- .../left/main/hooks/useOrderDiff.ts | 6 ++--- .../left/settings/SettingsEditProfile.tsx | 4 ++-- .../left/settings/WallpaperTile.tsx | 4 ++-- .../settings/folders/SettingsFoldersMain.tsx | 4 ++-- src/components/main/DeleteFolderDialog.tsx | 4 ++-- .../main/ForwardRecipientPicker.tsx | 4 ++-- .../main/premium/PremiumFeatureModal.tsx | 4 ++-- src/components/mediaViewer/MediaViewer.tsx | 14 ++++++------ .../middle/DeleteSelectedMessageModal.tsx | 4 ++-- src/components/middle/MessageListContent.tsx | 4 ++-- .../middle/MessageSelectToolbar.tsx | 4 ++-- src/components/middle/MiddleColumn.tsx | 4 ++-- src/components/middle/MiddleHeader.tsx | 4 ++-- .../middle/composer/AttachmentModal.tsx | 4 ++-- .../middle/composer/CustomEmojiTooltip.tsx | 4 ++-- src/components/middle/composer/DropArea.tsx | 4 ++-- .../middle/composer/InlineBotTooltip.tsx | 4 ++-- .../middle/composer/MentionTooltip.tsx | 4 ++-- .../middle/composer/StickerTooltip.tsx | 4 ++-- src/components/middle/message/Location.tsx | 4 ++-- src/components/middle/message/Message.tsx | 4 ++-- src/components/middle/message/Photo.tsx | 4 ++-- src/components/middle/message/RoundVideo.tsx | 4 ++-- src/components/middle/message/Video.tsx | 4 ++-- .../modals/chatlist/ChatlistModal.tsx | 6 ++--- .../transaction/StarsTransactionModal.tsx | 4 ++-- src/components/modals/webApp/WebAppModal.tsx | 10 ++++----- src/components/payment/PaymentModal.tsx | 6 ++--- src/components/right/AddChatMembers.tsx | 4 ++-- src/components/right/PollAnswerResults.tsx | 4 ++-- .../management/ManageChatPrivacyType.tsx | 4 ++-- src/components/story/StorySlides.tsx | 4 ++-- src/components/story/StoryViewer.tsx | 10 ++++----- src/components/ui/ShowTransition.tsx | 6 ++--- src/components/ui/TabList.tsx | 4 ++-- src/components/ui/Transition.tsx | 4 ++-- src/hooks/useCurrentOrPrev.ts | 4 ++-- src/hooks/useInfiniteScroll.ts | 6 ++--- src/hooks/usePrevDuringAnimation.ts | 4 ++-- src/hooks/usePrevious.ts | 22 +++++++++---------- src/hooks/usePrevious2.ts | 15 ------------- src/hooks/usePreviousDeprecated.ts | 20 +++++++++++++++++ src/hooks/useSyncEffect.ts | 4 ++-- 60 files changed, 163 insertions(+), 160 deletions(-) delete mode 100644 src/hooks/usePrevious2.ts create mode 100644 src/hooks/usePreviousDeprecated.ts diff --git a/src/components/App.tsx b/src/components/App.tsx index 47c607dd8..7fed0fe8a 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -20,7 +20,7 @@ import { updateSizes } from '../util/windowSize'; import useAppLayout from '../hooks/useAppLayout'; import useFlag from '../hooks/useFlag'; -import usePrevious from '../hooks/usePrevious'; +import usePreviousDeprecated from '../hooks/usePreviousDeprecated'; // import Test from './test/TestLocale'; import Auth from './auth/Auth'; @@ -180,7 +180,7 @@ const App: FC = ({ } }, [isInactiveAuth, markInactive, unmarkInactive]); - const prevActiveKey = usePrevious(activeKey); + const prevActiveKey = usePreviousDeprecated(activeKey); // eslint-disable-next-line consistent-return function renderContent() { diff --git a/src/components/calls/group/MicrophoneButton.tsx b/src/components/calls/group/MicrophoneButton.tsx index c75729927..5ad28e02c 100644 --- a/src/components/calls/group/MicrophoneButton.tsx +++ b/src/components/calls/group/MicrophoneButton.tsx @@ -12,7 +12,7 @@ import { vibrateShort } from '../../../util/vibrate'; import { LOCAL_TGS_URLS } from '../../common/helpers/animatedAssets'; import useOldLang from '../../../hooks/useOldLang'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import AnimatedIcon from '../../common/AnimatedIcon'; import Button from '../../ui/Button'; @@ -57,7 +57,7 @@ const MicrophoneButton: FC = ({ const [isRequestingToSpeak, setIsRequestingToSpeak] = useState(false); const isConnecting = connectionState !== 'connected'; const shouldRaiseHand = !canSelfUnmute && isMuted; - const prevShouldRaiseHand = usePrevious(shouldRaiseHand); + const prevShouldRaiseHand = usePreviousDeprecated(shouldRaiseHand); useEffect(() => { if (prevShouldRaiseHand && !shouldRaiseHand) { diff --git a/src/components/calls/group/OutlinedMicrophoneIcon.tsx b/src/components/calls/group/OutlinedMicrophoneIcon.tsx index 5b0ae7d21..a40fbc5a2 100644 --- a/src/components/calls/group/OutlinedMicrophoneIcon.tsx +++ b/src/components/calls/group/OutlinedMicrophoneIcon.tsx @@ -6,7 +6,7 @@ import type { GroupCallParticipant } from '../../../lib/secret-sauce'; import { THRESHOLD } from '../../../lib/secret-sauce'; import { LOCAL_TGS_URLS } from '../../common/helpers/animatedAssets'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import AnimatedIcon from '../../common/AnimatedIcon'; @@ -24,10 +24,10 @@ const OutlinedMicrophoneIcon: FC = ({ const { isMuted, isMutedByMe } = participant; const isSpeaking = (participant.amplitude || 0) > THRESHOLD; const isRaiseHand = Boolean(participant.raiseHandRating); - const prevIsRaiseHand = usePrevious(isRaiseHand); + const prevIsRaiseHand = usePreviousDeprecated(isRaiseHand); const canSelfUnmute = Boolean(participant?.canSelfUnmute); const shouldRaiseHand = !canSelfUnmute && isMuted; - const prevIsMuted = usePrevious(isMuted); + const prevIsMuted = usePreviousDeprecated(isMuted); const playSegment: [number, number] = useMemo(() => { if (isMuted && !prevIsMuted) { diff --git a/src/components/calls/group/hooks/useGroupCallVideoLayout.ts b/src/components/calls/group/hooks/useGroupCallVideoLayout.ts index 0b67723ab..e331f8220 100644 --- a/src/components/calls/group/hooks/useGroupCallVideoLayout.ts +++ b/src/components/calls/group/hooks/useGroupCallVideoLayout.ts @@ -4,7 +4,7 @@ import { } from '../../../../lib/teact/teact'; import useLastCallback from '../../../../hooks/useLastCallback'; -import usePrevious from '../../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../../hooks/usePreviousDeprecated'; import useResizeObserver from '../../../../hooks/useResizeObserver'; const PADDING_HORIZONTAL = 10; @@ -46,8 +46,8 @@ export default function useGroupCallVideoLayout({ const [videoLayout, setVideoLayout] = useState([]); const [panelOffset, setPanelOffset] = useState(0); const videosCount = videoParticipants.length; - const prevVideosCount = usePrevious(videosCount); - const prevVideoParticipants = usePrevious(videoParticipants); + const prevVideosCount = usePreviousDeprecated(videosCount); + const prevVideoParticipants = usePreviousDeprecated(videoParticipants); const removedVideoParticipants = useMemo(() => { return prevVideoParticipants?.filter( ({ id, type }) => !videoParticipants.some((p) => p.id === id && p.type === type), diff --git a/src/components/common/AnimatedCounter.tsx b/src/components/common/AnimatedCounter.tsx index cb558c8b0..e3975647e 100644 --- a/src/components/common/AnimatedCounter.tsx +++ b/src/components/common/AnimatedCounter.tsx @@ -8,7 +8,7 @@ import { throttleWithTickEnd } from '../../util/schedulers'; import useForceUpdate from '../../hooks/useForceUpdate'; import useLang from '../../hooks/useLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import styles from './AnimatedCounter.module.scss'; @@ -34,7 +34,7 @@ const AnimatedCounter: FC = ({ }) => { const { isRtl } = useLang(); - const prevText = usePrevious(text); + const prevText = usePreviousDeprecated(text); const forceUpdate = useForceUpdate(); const shouldAnimate = scheduleAnimation( diff --git a/src/components/common/CalendarModal.tsx b/src/components/common/CalendarModal.tsx index 50694ee67..a77081971 100644 --- a/src/components/common/CalendarModal.tsx +++ b/src/components/common/CalendarModal.tsx @@ -11,7 +11,7 @@ import { formatDateToString, formatTime, getDayStart } from '../../util/dates/da import useFlag from '../../hooks/useFlag'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import Button from '../ui/Button'; import Modal from '../ui/Modal'; @@ -73,7 +73,7 @@ const CalendarModal: FC = ({ }, [isPastMode, maxAt]); const passedSelectedDate = useMemo(() => (selectedAt ? new Date(selectedAt) : new Date()), [selectedAt]); - const prevIsOpen = usePrevious(isOpen); + const prevIsOpen = usePreviousDeprecated(isOpen); const [isTimeInputFocused, markTimeInputAsFocused] = useFlag(false); const [selectedDate, setSelectedDate] = useState(passedSelectedDate); diff --git a/src/components/common/Composer.tsx b/src/components/common/Composer.tsx index b583d1c5b..9171036b0 100644 --- a/src/components/common/Composer.tsx +++ b/src/components/common/Composer.tsx @@ -121,7 +121,7 @@ import useFlag from '../../hooks/useFlag'; import useGetSelectionRange from '../../hooks/useGetSelectionRange'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import useSchedule from '../../hooks/useSchedule'; import useSendMessageAction from '../../hooks/useSendMessageAction'; import useShowTransition from '../../hooks/useShowTransition'; @@ -418,7 +418,7 @@ const Composer: FC = ({ const [isMounted, setIsMounted] = useState(false); const getSelectionRange = useGetSelectionRange(editableInputCssSelector); const lastMessageSendTimeSeconds = useRef(); - const prevDropAreaState = usePrevious(dropAreaState); + const prevDropAreaState = usePreviousDeprecated(dropAreaState); const { width: windowWidth } = windowSize.get(); const isInMessageList = type === 'messageList'; diff --git a/src/components/common/CountryPickerModal.tsx b/src/components/common/CountryPickerModal.tsx index 01f5d4b5c..a3657a235 100644 --- a/src/components/common/CountryPickerModal.tsx +++ b/src/components/common/CountryPickerModal.tsx @@ -10,7 +10,7 @@ import buildClassName from '../../util/buildClassName'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import Button from '../ui/Button'; import Modal from '../ui/Modal'; @@ -39,7 +39,7 @@ const CountryPickerModal: FC = ({ const lang = useOldLang(); const [selectedCountryIds, setSelectedCountryIds] = useState([]); - const prevSelectedCountryIds = usePrevious(selectedCountryIds); + const prevSelectedCountryIds = usePreviousDeprecated(selectedCountryIds); const noPickerScrollRestore = prevSelectedCountryIds === selectedCountryIds; const displayedIds = useMemo(() => { diff --git a/src/components/common/CustomEmojiSetsModal.tsx b/src/components/common/CustomEmojiSetsModal.tsx index 31ca2ba9e..4274ad598 100644 --- a/src/components/common/CustomEmojiSetsModal.tsx +++ b/src/components/common/CustomEmojiSetsModal.tsx @@ -15,7 +15,7 @@ import buildClassName from '../../util/buildClassName'; import { useIntersectionObserver } from '../../hooks/useIntersectionObserver'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import Modal from '../ui/Modal'; import StickerSetCard from './StickerSetCard'; @@ -49,7 +49,7 @@ const CustomEmojiSetsModal: FC = ({ rootRef: customEmojiModalRef, isDisabled: !customEmojiSets, }); - const prevCustomEmojiSets = usePrevious(customEmojiSets); + const prevCustomEmojiSets = usePreviousDeprecated(customEmojiSets); const renderingCustomEmojiSets = customEmojiSets || prevCustomEmojiSets; const handleSetClick = useLastCallback((sticker: ApiSticker) => { diff --git a/src/components/common/DeleteMessageModal.tsx b/src/components/common/DeleteMessageModal.tsx index 8095db1b8..49ac3fcd3 100644 --- a/src/components/common/DeleteMessageModal.tsx +++ b/src/components/common/DeleteMessageModal.tsx @@ -33,7 +33,7 @@ import renderText from './helpers/renderText'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import useManagePermissions from '../right/hooks/useManagePermissions'; import PermissionCheckboxList from '../main/PermissionCheckboxList'; @@ -101,7 +101,7 @@ const DeleteMessageModal: FC = ({ closeDeleteMessageModal, } = getActions(); - const prevIsOpen = usePrevious(isOpen); + const prevIsOpen = usePreviousDeprecated(isOpen); const lang = useOldLang(); diff --git a/src/components/common/ManageUsernames.tsx b/src/components/common/ManageUsernames.tsx index bb3356945..dafcc8842 100644 --- a/src/components/common/ManageUsernames.tsx +++ b/src/components/common/ManageUsernames.tsx @@ -11,7 +11,7 @@ import { copyTextToClipboard } from '../../util/clipboard'; import { isBetween } from '../../util/math'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import ConfirmDialog from '../ui/ConfirmDialog'; import Draggable from '../ui/Draggable'; @@ -49,7 +49,7 @@ const ManageUsernames: FC = ({ const [usernameForConfirm, setUsernameForConfirm] = useState(); const usernameList = useMemo(() => usernames.map(({ username }) => username), [usernames]); - const prevUsernameList = usePrevious(usernameList); + const prevUsernameList = usePreviousDeprecated(usernameList); const [state, setState] = useState({ orderedUsernames: usernameList, diff --git a/src/components/common/ProfileInfo.tsx b/src/components/common/ProfileInfo.tsx index 76e26f305..48a158da4 100644 --- a/src/components/common/ProfileInfo.tsx +++ b/src/components/common/ProfileInfo.tsx @@ -26,7 +26,7 @@ import renderText from './helpers/renderText'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import usePhotosPreload from './hooks/usePhotosPreload'; import Transition from '../ui/Transition'; @@ -87,8 +87,8 @@ const ProfileInfo: FC = ({ const userProfilePhotos = user?.profilePhotos; const chatProfilePhotos = chat?.profilePhotos; const photos = userProfilePhotos?.photos || chatProfilePhotos?.photos || MEMO_EMPTY_ARRAY; - const prevMediaIndex = usePrevious(mediaIndex); - const prevAvatarOwnerId = usePrevious(avatarOwnerId); + const prevMediaIndex = usePreviousDeprecated(mediaIndex); + const prevAvatarOwnerId = usePreviousDeprecated(avatarOwnerId); const [hasSlideAnimation, setHasSlideAnimation] = useState(true); // slideOptimized doesn't work well when animation is dynamically disabled const slideAnimation = hasSlideAnimation ? (lang.isRtl ? 'slideRtl' : 'slide') : 'none'; diff --git a/src/components/common/StickerSetModal.tsx b/src/components/common/StickerSetModal.tsx index 773c1af28..7e9042907 100644 --- a/src/components/common/StickerSetModal.tsx +++ b/src/components/common/StickerSetModal.tsx @@ -27,7 +27,7 @@ import renderText from './helpers/renderText'; import useAppLayout from '../../hooks/useAppLayout'; import { useIntersectionObserver } from '../../hooks/useIntersectionObserver'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import useSchedule from '../../hooks/useSchedule'; import useScrolledState from '../../hooks/useScrolledState'; @@ -90,7 +90,7 @@ const StickerSetModal: FC = ({ const { isMobile } = useAppLayout(); - const prevStickerSet = usePrevious(stickerSet); + const prevStickerSet = usePreviousDeprecated(stickerSet); const renderingStickerSet = stickerSet || prevStickerSet; const isAdded = Boolean(!renderingStickerSet?.isArchived && renderingStickerSet?.installedDate); diff --git a/src/components/common/UsernameInput.tsx b/src/components/common/UsernameInput.tsx index 095d0deec..07e2efa5c 100644 --- a/src/components/common/UsernameInput.tsx +++ b/src/components/common/UsernameInput.tsx @@ -11,7 +11,7 @@ import { } from '../../util/username'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import InputText from '../ui/InputText'; @@ -43,7 +43,7 @@ const UsernameInput: FC = ({ const langPrefix = asLink ? 'SetUrl' : 'Username'; const label = asLink ? lang('SetUrlPlaceholder') : lang('Username'); - const previousIsUsernameAvailable = usePrevious(isUsernameAvailable); + const previousIsUsernameAvailable = usePreviousDeprecated(isUsernameAvailable); const renderingIsUsernameAvailable = currentUsername !== username ? (isUsernameAvailable ?? previousIsUsernameAvailable) : undefined; const isChecking = username && currentUsername !== username && checkedUsername !== username; diff --git a/src/components/left/LeftColumn.tsx b/src/components/left/LeftColumn.tsx index 51776fa09..abb309521 100644 --- a/src/components/left/LeftColumn.tsx +++ b/src/components/left/LeftColumn.tsx @@ -17,7 +17,7 @@ import { import useFoldersReducer from '../../hooks/reducers/useFoldersReducer'; import { useHotkeys } from '../../hooks/useHotkeys'; import useLastCallback from '../../hooks/useLastCallback'; -import usePrevious2 from '../../hooks/usePrevious2'; +import usePrevious from '../../hooks/usePrevious'; import { useStateRef } from '../../hooks/useStateRef'; import useSyncEffect from '../../hooks/useSyncEffect'; @@ -448,7 +448,7 @@ function LeftColumn({ setSettingsScreen(screen); }); - const prevSettingsScreenRef = useStateRef(usePrevious2(contentType === ContentType.Settings ? settingsScreen : -1)); + const prevSettingsScreenRef = useStateRef(usePrevious(contentType === ContentType.Settings ? settingsScreen : -1)); useEffect(() => { if (!IS_TOUCH_ENV) { diff --git a/src/components/left/main/ForumPanel.tsx b/src/components/left/main/ForumPanel.tsx index 904e33a05..9dc1e1852 100644 --- a/src/components/left/main/ForumPanel.tsx +++ b/src/components/left/main/ForumPanel.tsx @@ -28,7 +28,7 @@ import useInfiniteScroll from '../../../hooks/useInfiniteScroll'; import { useIntersectionObserver, useOnIntersect } from '../../../hooks/useIntersectionObserver'; import useLastCallback from '../../../hooks/useLastCallback'; import useOldLang from '../../../hooks/useOldLang'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useOrderDiff from './hooks/useOrderDiff'; import GroupCallTopPane from '../../calls/group/GroupCallTopPane'; @@ -129,7 +129,7 @@ const ForumPanel: FC = ({ const shouldRenderRef = useRef(false); const isVisible = isOpen && !isHidden; - const prevIsVisible = usePrevious(isVisible); + const prevIsVisible = usePreviousDeprecated(isVisible); if (prevIsVisible !== isVisible) { shouldRenderRef.current = false; diff --git a/src/components/left/main/hooks/useLeftHeaderButtonRtlForumTransition.ts b/src/components/left/main/hooks/useLeftHeaderButtonRtlForumTransition.ts index 54d9881e8..2955cfd36 100644 --- a/src/components/left/main/hooks/useLeftHeaderButtonRtlForumTransition.ts +++ b/src/components/left/main/hooks/useLeftHeaderButtonRtlForumTransition.ts @@ -1,12 +1,12 @@ import { useRef } from '../../../../lib/teact/teact'; import useForceUpdate from '../../../../hooks/useForceUpdate'; -import usePrevious from '../../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../../hooks/usePreviousDeprecated'; export default function useLeftHeaderButtonRtlForumTransition(shouldHideSearch?: boolean) { const forceUpdate = useForceUpdate(); const shouldDisableDropdownMenuTransitionRef = useRef(shouldHideSearch); - const prevShouldHideSearch = usePrevious(shouldHideSearch); + const prevShouldHideSearch = usePreviousDeprecated(shouldHideSearch); function handleDropdownMenuTransitionEnd() { shouldDisableDropdownMenuTransitionRef.current = Boolean(shouldHideSearch); diff --git a/src/components/left/main/hooks/useOrderDiff.ts b/src/components/left/main/hooks/useOrderDiff.ts index 3b79230c8..9992b413a 100644 --- a/src/components/left/main/hooks/useOrderDiff.ts +++ b/src/components/left/main/hooks/useOrderDiff.ts @@ -3,7 +3,7 @@ import { useMemo } from '../../../../lib/teact/teact'; import { mapValues } from '../../../../util/iteratees'; import { useChatAnimationType } from './useChatAnimationType'; -import usePrevious from '../../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../../hooks/usePreviousDeprecated'; export default function useOrderDiff(orderedIds: (string | number)[] | undefined, key?: string) { const orderById = useMemo(() => { @@ -17,8 +17,8 @@ export default function useOrderDiff(orderedIds: (string | number)[] | undefined }, {} as Record); }, [orderedIds]); - const prevOrderById = usePrevious(orderById); - const prevChatId = usePrevious(key); + const prevOrderById = usePreviousDeprecated(orderById); + const prevChatId = usePreviousDeprecated(key); const orderDiffById = useMemo(() => { if (!orderById || !prevOrderById || key !== prevChatId) { diff --git a/src/components/left/settings/SettingsEditProfile.tsx b/src/components/left/settings/SettingsEditProfile.tsx index 54d0b416c..b5c09bd82 100644 --- a/src/components/left/settings/SettingsEditProfile.tsx +++ b/src/components/left/settings/SettingsEditProfile.tsx @@ -20,7 +20,7 @@ import renderText from '../../common/helpers/renderText'; import useHistoryBack from '../../../hooks/useHistoryBack'; import useMedia from '../../../hooks/useMedia'; import useOldLang from '../../../hooks/useOldLang'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import ManageUsernames from '../../common/ManageUsernames'; import SafeLink from '../../common/SafeLink'; @@ -91,7 +91,7 @@ const SettingsEditProfile: FC = ({ const isLoading = progress === ProfileEditProgress.InProgress; const isUsernameError = editableUsername === false; - const previousIsUsernameAvailable = usePrevious(isUsernameAvailable); + const previousIsUsernameAvailable = usePreviousDeprecated(isUsernameAvailable); const renderingIsUsernameAvailable = isUsernameAvailable ?? previousIsUsernameAvailable; const shouldRenderUsernamesManage = usernames && usernames.length > 1; diff --git a/src/components/left/settings/WallpaperTile.tsx b/src/components/left/settings/WallpaperTile.tsx index eeb432fe4..31e29cfea 100644 --- a/src/components/left/settings/WallpaperTile.tsx +++ b/src/components/left/settings/WallpaperTile.tsx @@ -16,7 +16,7 @@ import { fetchBlob } from '../../../util/files'; import useCanvasBlur from '../../../hooks/useCanvasBlur'; import useMedia from '../../../hooks/useMedia'; import useMediaWithLoadProgress from '../../../hooks/useMediaWithLoadProgress'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useShowTransition from '../../../hooks/useShowTransition'; import ProgressSpinner from '../../ui/ProgressSpinner'; @@ -52,7 +52,7 @@ const WallpaperTile: FC = ({ const { mediaData: fullMedia, loadProgress, } = useMediaWithLoadProgress(localMediaHash, !isLoadAllowed); - const wasLoadDisabled = usePrevious(isLoadAllowed) === false; + const wasLoadDisabled = usePreviousDeprecated(isLoadAllowed) === false; const { shouldRender: shouldRenderSpinner, transitionClassNames: spinnerClassNames } = useShowTransition( (isLoadAllowed && !fullMedia) || slug === UPLOADING_WALLPAPER_SLUG, undefined, diff --git a/src/components/left/settings/folders/SettingsFoldersMain.tsx b/src/components/left/settings/folders/SettingsFoldersMain.tsx index 708ceb5d1..3d4af530e 100644 --- a/src/components/left/settings/folders/SettingsFoldersMain.tsx +++ b/src/components/left/settings/folders/SettingsFoldersMain.tsx @@ -19,7 +19,7 @@ import renderText from '../../../common/helpers/renderText'; import { useFolderManagerForChatsCount } from '../../../../hooks/useFolderManager'; import useHistoryBack from '../../../../hooks/useHistoryBack'; import useOldLang from '../../../../hooks/useOldLang'; -import usePrevious from '../../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../../hooks/usePreviousDeprecated'; import AnimatedIcon from '../../../common/AnimatedIcon'; import Button from '../../../ui/Button'; @@ -76,7 +76,7 @@ const SettingsFoldersMain: FC = ({ draggedIndex: undefined, }); - const prevFolderIds = usePrevious(folderIds); + const prevFolderIds = usePreviousDeprecated(folderIds); // Sync folders state after changing folders in other clients useEffect(() => { diff --git a/src/components/main/DeleteFolderDialog.tsx b/src/components/main/DeleteFolderDialog.tsx index b7f497bcf..0f22f6c24 100644 --- a/src/components/main/DeleteFolderDialog.tsx +++ b/src/components/main/DeleteFolderDialog.tsx @@ -5,7 +5,7 @@ import { getActions } from '../../global'; import type { ApiChatFolder } from '../../api/types'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import ConfirmDialog from '../ui/ConfirmDialog'; @@ -21,7 +21,7 @@ const DeleteFolderDialog: FC = ({ const isOpen = Boolean(folder); - const renderingFolder = usePrevious(folder) || folder; + const renderingFolder = usePreviousDeprecated(folder) || folder; const isMyChatlist = renderingFolder?.hasMyInvites; const handleDeleteFolderMessage = useCallback(() => { diff --git a/src/components/main/ForwardRecipientPicker.tsx b/src/components/main/ForwardRecipientPicker.tsx index b8fae3e1c..cd3e93e77 100644 --- a/src/components/main/ForwardRecipientPicker.tsx +++ b/src/components/main/ForwardRecipientPicker.tsx @@ -15,7 +15,7 @@ import { import useFlag from '../../hooks/useFlag'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import RecipientPicker from '../common/RecipientPicker'; @@ -48,7 +48,7 @@ const ForwardRecipientPicker: FC = ({ const lang = useOldLang(); - const renderingIsStory = usePrevious(isStory, true); + const renderingIsStory = usePreviousDeprecated(isStory, true); const [isShown, markIsShown, unmarkIsShown] = useFlag(); useEffect(() => { if (isOpen) { diff --git a/src/components/main/premium/PremiumFeatureModal.tsx b/src/components/main/premium/PremiumFeatureModal.tsx index 415a99343..78cdccaf0 100644 --- a/src/components/main/premium/PremiumFeatureModal.tsx +++ b/src/components/main/premium/PremiumFeatureModal.tsx @@ -17,7 +17,7 @@ import renderText from '../../common/helpers/renderText'; import useFlag from '../../../hooks/useFlag'; import useLastCallback from '../../../hooks/useLastCallback'; import useOldLang from '../../../hooks/useOldLang'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import SliderDots from '../../common/SliderDots'; import Button from '../../ui/Button'; @@ -129,7 +129,7 @@ const PremiumFeatureModal: FC = ({ const [isScrolledToTop, setIsScrolledToTop] = useState(true); const [isScrolledToBottom, setIsScrolledToBottom] = useState(false); - const prevInitialSection = usePrevious(initialSection); + const prevInitialSection = usePreviousDeprecated(initialSection); const filteredSections = useMemo(() => { if (!premiumPromoOrder) return PREMIUM_FEATURE_SECTIONS; diff --git a/src/components/mediaViewer/MediaViewer.tsx b/src/components/mediaViewer/MediaViewer.tsx index be90e5658..583221957 100644 --- a/src/components/mediaViewer/MediaViewer.tsx +++ b/src/components/mediaViewer/MediaViewer.tsx @@ -44,7 +44,7 @@ import { dispatchHeavyAnimationEvent } from '../../hooks/useHeavyAnimationCheck' import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; import { exitPictureInPictureIfNeeded, usePictureInPictureSignal } from '../../hooks/usePictureInPicture'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import { dispatchPriorityPlaybackEvent } from '../../hooks/usePriorityPlaybackCheck'; import { useMediaProps } from './hooks/useMediaProps'; @@ -120,7 +120,7 @@ const MediaViewer = ({ /* Animation */ const animationKey = useRef(); const senderId = message?.senderId || avatarOwner?.id; - const prevSenderId = usePrevious(senderId); + const prevSenderId = usePreviousDeprecated(senderId); const headerAnimation = withAnimation ? 'slideFade' : 'none'; const isGhostAnimation = Boolean(withAnimation && !shouldSkipHistoryAnimations); @@ -201,11 +201,11 @@ const MediaViewer = ({ }; }, [forceUpdate]); - const prevMessage = usePrevious(message); - const prevIsHidden = usePrevious(isHidden); - const prevOrigin = usePrevious(origin); - const prevItem = usePrevious(currentItem); - const prevBestImageData = usePrevious(bestImageData); + const prevMessage = usePreviousDeprecated(message); + const prevIsHidden = usePreviousDeprecated(isHidden); + const prevOrigin = usePreviousDeprecated(origin); + const prevItem = usePreviousDeprecated(currentItem); + const prevBestImageData = usePreviousDeprecated(bestImageData); const textParts = message ? renderMessageText({ message, forcePlayback: true, isForMediaViewer: true }) : undefined; const hasFooter = Boolean(textParts); const shouldAnimateOpening = prevIsHidden && prevItem !== currentItem; diff --git a/src/components/middle/DeleteSelectedMessageModal.tsx b/src/components/middle/DeleteSelectedMessageModal.tsx index 9f3727814..46886129a 100644 --- a/src/components/middle/DeleteSelectedMessageModal.tsx +++ b/src/components/middle/DeleteSelectedMessageModal.tsx @@ -37,7 +37,7 @@ import renderText from '../common/helpers/renderText'; import useLang from '../../hooks/useLang'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import useManagePermissions from '../right/hooks/useManagePermissions'; import Avatar from '../common/Avatar'; @@ -100,7 +100,7 @@ const DeleteSelectedMessageModal: FC = ({ updateChatMemberBannedRights, } = getActions(); - const prevIsOpen = usePrevious(isOpen); + const prevIsOpen = usePreviousDeprecated(isOpen); const oldLang = useOldLang(); const lang = useLang(); diff --git a/src/components/middle/MessageListContent.tsx b/src/components/middle/MessageListContent.tsx index 24fd142ba..ca380bc3b 100644 --- a/src/components/middle/MessageListContent.tsx +++ b/src/components/middle/MessageListContent.tsx @@ -27,7 +27,7 @@ import { preventMessageInputBlur } from './helpers/preventMessageInputBlur'; import useDerivedSignal from '../../hooks/useDerivedSignal'; import { getIsHeavyAnimating } from '../../hooks/useHeavyAnimationCheck'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import useMessageObservers from './hooks/useMessageObservers'; import useScrollHooks from './hooks/useScrollHooks'; @@ -139,7 +139,7 @@ const MessageListContent: FC = ({ }, 0); let appearanceIndex = 0; - const prevMessageIds = usePrevious(messageIds); + const prevMessageIds = usePreviousDeprecated(messageIds); const isNewMessage = Boolean( messageIds && prevMessageIds && messageIds[messageIds.length - 2] === prevMessageIds[prevMessageIds.length - 1], ); diff --git a/src/components/middle/MessageSelectToolbar.tsx b/src/components/middle/MessageSelectToolbar.tsx index 39141c60e..a383a4b45 100644 --- a/src/components/middle/MessageSelectToolbar.tsx +++ b/src/components/middle/MessageSelectToolbar.tsx @@ -20,7 +20,7 @@ import captureKeyboardListeners from '../../util/captureKeyboardListeners'; import useFlag from '../../hooks/useFlag'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import useCopySelectedMessages from './hooks/useCopySelectedMessages'; import ReportModal from '../common/ReportModal'; @@ -105,7 +105,7 @@ const MessageSelectToolbar: FC = ({ exitMessageSelectMode(); }); - const prevSelectedMessagesCount = usePrevious(selectedMessagesCount || undefined, true); + const prevSelectedMessagesCount = usePreviousDeprecated(selectedMessagesCount || undefined, true); const renderingSelectedMessagesCount = isActive ? selectedMessagesCount : prevSelectedMessagesCount; const formattedMessagesCount = lang('VoiceOver.Chat.MessagesSelected', renderingSelectedMessagesCount, 'i'); diff --git a/src/components/middle/MiddleColumn.tsx b/src/components/middle/MiddleColumn.tsx index 81fa046bd..995c33b2a 100644 --- a/src/components/middle/MiddleColumn.tsx +++ b/src/components/middle/MiddleColumn.tsx @@ -72,7 +72,7 @@ import useHistoryBack from '../../hooks/useHistoryBack'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; import usePrevDuringAnimation from '../../hooks/usePrevDuringAnimation'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import { useResize } from '../../hooks/useResize'; import useSyncEffect from '../../hooks/useSyncEffect'; import useWindowSize from '../../hooks/window/useWindowSize'; @@ -286,7 +286,7 @@ function MiddleColumn({ closeAnimationDuration, ); - const prevTransitionKey = usePrevious(currentTransitionKey); + const prevTransitionKey = usePreviousDeprecated(currentTransitionKey); const cleanupExceptionKey = ( prevTransitionKey !== undefined && prevTransitionKey < currentTransitionKey ? prevTransitionKey : undefined diff --git a/src/components/middle/MiddleHeader.tsx b/src/components/middle/MiddleHeader.tsx index 413f54d52..ff92b8802 100644 --- a/src/components/middle/MiddleHeader.tsx +++ b/src/components/middle/MiddleHeader.tsx @@ -62,7 +62,7 @@ import useEnsureMessage from '../../hooks/useEnsureMessage'; import useLastCallback from '../../hooks/useLastCallback'; import useLongPress from '../../hooks/useLongPress'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import useShowTransition from '../../hooks/useShowTransition'; import useWindowSize from '../../hooks/window/useWindowSize'; @@ -330,7 +330,7 @@ const MiddleHeader: FC = ({ const renderingCanUnpin = useCurrentOrPrev(canUnpin, true); const renderingPinnedMessageTitle = useCurrentOrPrev(topMessageTitle); - const prevTransitionKey = usePrevious(currentTransitionKey); + const prevTransitionKey = usePreviousDeprecated(currentTransitionKey); const cleanupExceptionKey = ( prevTransitionKey !== undefined && prevTransitionKey < currentTransitionKey ? prevTransitionKey : undefined ); diff --git a/src/components/middle/composer/AttachmentModal.tsx b/src/components/middle/composer/AttachmentModal.tsx index c4966ad63..d6825df75 100644 --- a/src/components/middle/composer/AttachmentModal.tsx +++ b/src/components/middle/composer/AttachmentModal.tsx @@ -37,7 +37,7 @@ import useFlag from '../../../hooks/useFlag'; import useGetSelectionRange from '../../../hooks/useGetSelectionRange'; import useLastCallback from '../../../hooks/useLastCallback'; import useOldLang from '../../../hooks/useOldLang'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useScrolledState from '../../../hooks/useScrolledState'; import useCustomEmojiTooltip from './hooks/useCustomEmojiTooltip'; import useEmojiTooltip from './hooks/useEmojiTooltip'; @@ -149,7 +149,7 @@ const AttachmentModal: FC = ({ const inputRef = useRef(null); const hideTimeoutRef = useRef(); - const prevAttachments = usePrevious(attachments); + const prevAttachments = usePreviousDeprecated(attachments); const renderingAttachments = attachments.length ? attachments : prevAttachments; const { isMobile } = useAppLayout(); diff --git a/src/components/middle/composer/CustomEmojiTooltip.tsx b/src/components/middle/composer/CustomEmojiTooltip.tsx index dde633c94..109e78b62 100644 --- a/src/components/middle/composer/CustomEmojiTooltip.tsx +++ b/src/components/middle/composer/CustomEmojiTooltip.tsx @@ -13,7 +13,7 @@ import captureEscKeyListener from '../../../util/captureEscKeyListener'; import useHorizontalScroll from '../../../hooks/useHorizontalScroll'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; import useLastCallback from '../../../hooks/useLastCallback'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useShowTransition from '../../../hooks/useShowTransition'; import StickerButton from '../../common/StickerButton'; @@ -53,7 +53,7 @@ const CustomEmojiTooltip: FC = ({ // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); const { shouldRender, transitionClassNames } = useShowTransition(isOpen, undefined, undefined, false); - const prevStickers = usePrevious(customEmoji, true); + const prevStickers = usePreviousDeprecated(customEmoji, true); const displayedStickers = customEmoji || prevStickers; useHorizontalScroll(containerRef); diff --git a/src/components/middle/composer/DropArea.tsx b/src/components/middle/composer/DropArea.tsx index 252d26638..037f46fec 100644 --- a/src/components/middle/composer/DropArea.tsx +++ b/src/components/middle/composer/DropArea.tsx @@ -12,7 +12,7 @@ import getFilesFromDataTransferItems from './helpers/getFilesFromDataTransferIte import useLastCallback from '../../../hooks/useLastCallback'; import useOldLang from '../../../hooks/useOldLang'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useShowTransition from '../../../hooks/useShowTransition'; import Portal from '../../ui/Portal'; @@ -43,7 +43,7 @@ const DropArea: FC = ({ const { showNotification } = getActions(); // eslint-disable-next-line no-null/no-null const hideTimeoutRef = useRef(null); - const prevWithQuick = usePrevious(withQuick); + const prevWithQuick = usePreviousDeprecated(withQuick); const { shouldRender, transitionClassNames } = useShowTransition(isOpen); const isInAlbum = editingMessage && editingMessage?.groupedId; diff --git a/src/components/middle/composer/InlineBotTooltip.tsx b/src/components/middle/composer/InlineBotTooltip.tsx index d2bf02983..d0e8f7341 100644 --- a/src/components/middle/composer/InlineBotTooltip.tsx +++ b/src/components/middle/composer/InlineBotTooltip.tsx @@ -16,7 +16,7 @@ import { IS_TOUCH_ENV } from '../../../util/windowEnvironment'; import useCurrentOrPrev from '../../../hooks/useCurrentOrPrev'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; import useLastCallback from '../../../hooks/useLastCallback'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useShowTransition from '../../../hooks/useShowTransition'; import { useKeyboardNavigation } from './hooks/useKeyboardNavigation'; @@ -117,7 +117,7 @@ const InlineBotTooltip: FC = ({ }); }); - const prevInlineBotResults = usePrevious( + const prevInlineBotResults = usePreviousDeprecated( inlineBotResults?.length ? inlineBotResults : undefined, diff --git a/src/components/middle/composer/MentionTooltip.tsx b/src/components/middle/composer/MentionTooltip.tsx index e46b68c1a..fe0f69182 100644 --- a/src/components/middle/composer/MentionTooltip.tsx +++ b/src/components/middle/composer/MentionTooltip.tsx @@ -8,7 +8,7 @@ import buildClassName from '../../../util/buildClassName'; import setTooltipItemVisible from '../../../util/setTooltipItemVisible'; import useLastCallback from '../../../hooks/useLastCallback'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useShowTransition from '../../../hooks/useShowTransition'; import { useKeyboardNavigation } from './hooks/useKeyboardNavigation'; @@ -74,7 +74,7 @@ const MentionTooltip: FC = ({ } }, [filteredUsers, onClose]); - const prevChatMembers = usePrevious( + const prevChatMembers = usePreviousDeprecated( filteredUsers?.length ? filteredUsers : undefined, diff --git a/src/components/middle/composer/StickerTooltip.tsx b/src/components/middle/composer/StickerTooltip.tsx index ad33e591e..0bd08e2d1 100644 --- a/src/components/middle/composer/StickerTooltip.tsx +++ b/src/components/middle/composer/StickerTooltip.tsx @@ -11,7 +11,7 @@ import buildClassName from '../../../util/buildClassName'; import captureEscKeyListener from '../../../util/captureEscKeyListener'; import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useSendMessageAction from '../../../hooks/useSendMessageAction'; import useShowTransition from '../../../hooks/useShowTransition'; @@ -49,7 +49,7 @@ const StickerTooltip: FC = ({ // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); const { shouldRender, transitionClassNames } = useShowTransition(isOpen, undefined, undefined, false); - const prevStickers = usePrevious(stickers, true); + const prevStickers = usePreviousDeprecated(stickers, true); const displayedStickers = stickers || prevStickers; const sendMessageAction = useSendMessageAction(chatId, threadId); diff --git a/src/components/middle/message/Location.tsx b/src/components/middle/message/Location.tsx index 9e6fa5960..7bb4eed4d 100644 --- a/src/components/middle/message/Location.tsx +++ b/src/components/middle/message/Location.tsx @@ -26,7 +26,7 @@ import useForceUpdate from '../../../hooks/useForceUpdate'; import useLastCallback from '../../../hooks/useLastCallback'; import useMedia from '../../../hooks/useMedia'; import useOldLang from '../../../hooks/useOldLang'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useDevicePixelRatio from '../../../hooks/window/useDevicePixelRatio'; import Avatar from '../../common/Avatar'; @@ -81,7 +81,7 @@ const Location: FC = ({ const mediaHash = buildStaticMapHash(point, width, height, zoom, dpr); const mediaBlobUrl = useMedia(mediaHash); - const prevMediaBlobUrl = usePrevious(mediaBlobUrl, true); + const prevMediaBlobUrl = usePreviousDeprecated(mediaBlobUrl, true); const mapBlobUrl = mediaBlobUrl || prevMediaBlobUrl; const accuracyRadiusPx = useMemo(() => { diff --git a/src/components/middle/message/Message.tsx b/src/components/middle/message/Message.tsx index 72cf4be9f..13f3dd2bb 100644 --- a/src/components/middle/message/Message.tsx +++ b/src/components/middle/message/Message.tsx @@ -130,7 +130,7 @@ import { dispatchHeavyAnimationEvent } from '../../../hooks/useHeavyAnimationChe import { useOnIntersect } from '../../../hooks/useIntersectionObserver'; import useLastCallback from '../../../hooks/useLastCallback'; import useOldLang from '../../../hooks/useOldLang'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useResizeObserver from '../../../hooks/useResizeObserver'; import useShowTransition from '../../../hooks/useShowTransition'; import useTextLanguage from '../../../hooks/useTextLanguage'; @@ -720,7 +720,7 @@ const Message: FC = ({ chatTranslations, chatId, shouldTranslate ? messageId : undefined, requestedTranslationLanguage, ); // Used to display previous result while new one is loading - const previousTranslatedText = usePrevious(translatedText, Boolean(shouldTranslate)); + const previousTranslatedText = usePreviousDeprecated(translatedText, Boolean(shouldTranslate)); const currentTranslatedText = translatedText || previousTranslatedText; diff --git a/src/components/middle/message/Photo.tsx b/src/components/middle/message/Photo.tsx index 56ee3718d..0bc362df8 100644 --- a/src/components/middle/message/Photo.tsx +++ b/src/components/middle/message/Photo.tsx @@ -24,7 +24,7 @@ import useLastCallback from '../../../hooks/useLastCallback'; import useLayoutEffectWithPrevDeps from '../../../hooks/useLayoutEffectWithPrevDeps'; import useMediaTransition from '../../../hooks/useMediaTransition'; import useMediaWithLoadProgress from '../../../hooks/useMediaWithLoadProgress'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useShowTransition from '../../../hooks/useShowTransition'; import useBlurredMediaThumbRef from './hooks/useBlurredMediaThumbRef'; @@ -134,7 +134,7 @@ const Photo = ({ shouldLoad && !fullMediaData, uploadProgress !== undefined, ); - const wasLoadDisabled = usePrevious(isLoadAllowed) === false; + const wasLoadDisabled = usePreviousDeprecated(isLoadAllowed) === false; const { shouldRender: shouldRenderSpinner, diff --git a/src/components/middle/message/RoundVideo.tsx b/src/components/middle/message/RoundVideo.tsx index 4dd83b3bb..48b225fbb 100644 --- a/src/components/middle/message/RoundVideo.tsx +++ b/src/components/middle/message/RoundVideo.tsx @@ -27,7 +27,7 @@ import { useIsIntersecting } from '../../../hooks/useIntersectionObserver'; import useLastCallback from '../../../hooks/useLastCallback'; import useMediaTransition from '../../../hooks/useMediaTransition'; import useMediaWithLoadProgress from '../../../hooks/useMediaWithLoadProgress'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useShowTransition from '../../../hooks/useShowTransition'; import useBlurredMediaThumbRef from './hooks/useBlurredMediaThumbRef'; @@ -104,7 +104,7 @@ const RoundVideo: FC = ({ const thumbClassNames = useMediaTransition(!noThumb); const thumbDataUri = getMessageMediaThumbDataUri(message); const isTransferring = (isLoadAllowed && !isPlayerReady) || isDownloading; - const wasLoadDisabled = usePrevious(isLoadAllowed) === false; + const wasLoadDisabled = usePreviousDeprecated(isLoadAllowed) === false; const { shouldRender: shouldSpinnerRender, diff --git a/src/components/middle/message/Video.tsx b/src/components/middle/message/Video.tsx index e0e827e84..4aed92775 100644 --- a/src/components/middle/message/Video.tsx +++ b/src/components/middle/message/Video.tsx @@ -25,7 +25,7 @@ import useLastCallback from '../../../hooks/useLastCallback'; import useMedia from '../../../hooks/useMedia'; import useMediaTransition from '../../../hooks/useMediaTransition'; import useMediaWithLoadProgress from '../../../hooks/useMediaWithLoadProgress'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useShowTransition from '../../../hooks/useShowTransition'; import useBlurredMediaThumbRef from './hooks/useBlurredMediaThumbRef'; @@ -152,7 +152,7 @@ const Video = ({ uploadProgress !== undefined, ); - const wasLoadDisabled = usePrevious(isLoadAllowed) === false; + const wasLoadDisabled = usePreviousDeprecated(isLoadAllowed) === false; const { shouldRender: shouldRenderSpinner, transitionClassNames: spinnerClassNames, diff --git a/src/components/modals/chatlist/ChatlistModal.tsx b/src/components/modals/chatlist/ChatlistModal.tsx index c0feea9ba..da0b30fe6 100644 --- a/src/components/modals/chatlist/ChatlistModal.tsx +++ b/src/components/modals/chatlist/ChatlistModal.tsx @@ -8,7 +8,7 @@ import type { TabState } from '../../../global/types'; import { selectChatFolder } from '../../../global/selectors'; import useOldLang from '../../../hooks/useOldLang'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import Modal from '../../ui/Modal'; import Tab from '../../ui/Tab'; @@ -35,8 +35,8 @@ const ChatlistInviteModal: FC = ({ const lang = useOldLang(); const isOpen = Boolean(modal); - const renderingInfo = usePrevious(modal) || modal; - const renderingFolder = usePrevious(folder) || folder; + const renderingInfo = usePreviousDeprecated(modal) || modal; + const renderingFolder = usePreviousDeprecated(folder) || folder; const title = useMemo(() => { if (!renderingInfo) return undefined; diff --git a/src/components/modals/stars/transaction/StarsTransactionModal.tsx b/src/components/modals/stars/transaction/StarsTransactionModal.tsx index ff7340e4d..eb67b9b2b 100644 --- a/src/components/modals/stars/transaction/StarsTransactionModal.tsx +++ b/src/components/modals/stars/transaction/StarsTransactionModal.tsx @@ -24,7 +24,7 @@ import renderText from '../../../common/helpers/renderText'; import useLang from '../../../../hooks/useLang'; import useLastCallback from '../../../../hooks/useLastCallback'; import useOldLang from '../../../../hooks/useOldLang'; -import usePrevious from '../../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../../hooks/usePreviousDeprecated'; import AnimatedIconFromSticker from '../../../common/AnimatedIconFromSticker'; import Icon from '../../../common/icons/Icon'; @@ -243,7 +243,7 @@ const StarsTransactionModal: FC = ({ }; }, [transaction, oldLang, peer, isGift, animatedStickerData, giftOutAboutText, giftEntryAboutText]); - const prevModalData = usePrevious(starModalData); + const prevModalData = usePreviousDeprecated(starModalData); const renderingModalData = prevModalData || starModalData; return ( diff --git a/src/components/modals/webApp/WebAppModal.tsx b/src/components/modals/webApp/WebAppModal.tsx index 7b9b47174..bfa8e7cf7 100644 --- a/src/components/modals/webApp/WebAppModal.tsx +++ b/src/components/modals/webApp/WebAppModal.tsx @@ -27,7 +27,7 @@ import useAppLayout from '../../../hooks/useAppLayout'; import useFlag from '../../../hooks/useFlag'; import useLastCallback from '../../../hooks/useLastCallback'; import useOldLang from '../../../hooks/useOldLang'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import useSyncEffect from '../../../hooks/useSyncEffect'; import usePopupLimit from './hooks/usePopupLimit'; import useWebAppFrame from './hooks/useWebAppFrame'; @@ -561,10 +561,10 @@ const WebAppModal: FC = ({ ); } - const prevMainButtonColor = usePrevious(mainButton?.color, true); - const prevMainButtonTextColor = usePrevious(mainButton?.textColor, true); - const prevMainButtonIsActive = usePrevious(mainButton && Boolean(mainButton.isActive), true); - const prevMainButtonText = usePrevious(mainButton?.text, true); + const prevMainButtonColor = usePreviousDeprecated(mainButton?.color, true); + const prevMainButtonTextColor = usePreviousDeprecated(mainButton?.textColor, true); + const prevMainButtonIsActive = usePreviousDeprecated(mainButton && Boolean(mainButton.isActive), true); + const prevMainButtonText = usePreviousDeprecated(mainButton?.text, true); const mainButtonCurrentColor = mainButton?.color || prevMainButtonColor; const mainButtonCurrentTextColor = mainButton?.textColor || prevMainButtonTextColor; diff --git a/src/components/payment/PaymentModal.tsx b/src/components/payment/PaymentModal.tsx index 993a05c19..9b565d58e 100644 --- a/src/components/payment/PaymentModal.tsx +++ b/src/components/payment/PaymentModal.tsx @@ -22,7 +22,7 @@ import usePaymentReducer from '../../hooks/reducers/usePaymentReducer'; import useFlag from '../../hooks/useFlag'; import useLastCallback from '../../hooks/useLastCallback'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import Button from '../ui/Button'; import Modal from '../ui/Modal'; @@ -135,8 +135,8 @@ const PaymentModal: FC = ({ const [isLoading, setIsLoading] = useState(false); const [isTosAccepted, setIsTosAccepted] = useState(false); const [twoFaPassword, setTwoFaPassword] = useState(''); - const prevStep = usePrevious(step, true); - const prevRequestId = usePrevious(requestId); + const prevStep = usePreviousDeprecated(step, true); + const prevRequestId = usePreviousDeprecated(requestId); const canRenderFooter = step !== PaymentStep.ConfirmPayment; const setStep = useCallback((nextStep) => { diff --git a/src/components/right/AddChatMembers.tsx b/src/components/right/AddChatMembers.tsx index 9e979ced2..b9ee283f1 100644 --- a/src/components/right/AddChatMembers.tsx +++ b/src/components/right/AddChatMembers.tsx @@ -18,7 +18,7 @@ import sortChatIds from '../common/helpers/sortChatIds'; import useHistoryBack from '../../hooks/useHistoryBack'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import PeerPicker from '../common/pickers/PeerPicker'; import FloatingActionButton from '../ui/FloatingActionButton'; @@ -63,7 +63,7 @@ const AddChatMembers: FC = ({ const lang = useOldLang(); const [selectedMemberIds, setSelectedMemberIds] = useState([]); - const prevSelectedMemberIds = usePrevious(selectedMemberIds); + const prevSelectedMemberIds = usePreviousDeprecated(selectedMemberIds); const noPickerScrollRestore = prevSelectedMemberIds === selectedMemberIds; useHistoryBack({ diff --git a/src/components/right/PollAnswerResults.tsx b/src/components/right/PollAnswerResults.tsx index 75df1a3c9..4e82cc843 100644 --- a/src/components/right/PollAnswerResults.tsx +++ b/src/components/right/PollAnswerResults.tsx @@ -17,7 +17,7 @@ import { selectTabState } from '../../global/selectors'; import { renderTextWithEntities } from '../common/helpers/renderTextWithEntities'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import GroupChatInfo from '../common/GroupChatInfo'; import PrivateChatInfo from '../common/PrivateChatInfo'; @@ -58,7 +58,7 @@ const PollAnswerResults: FC = ({ closePollResults, } = getActions(); - const prevVotersCount = usePrevious(answerVote.votersCount); + const prevVotersCount = usePreviousDeprecated(answerVote.votersCount); const [isLoading, setIsLoading] = useState(true); const areVotersLoaded = Boolean(voters); const { option, text } = answer; diff --git a/src/components/right/management/ManageChatPrivacyType.tsx b/src/components/right/management/ManageChatPrivacyType.tsx index e197f14a8..a2c399061 100644 --- a/src/components/right/management/ManageChatPrivacyType.tsx +++ b/src/components/right/management/ManageChatPrivacyType.tsx @@ -19,7 +19,7 @@ import { selectCurrentLimit } from '../../../global/selectors/limits'; import useFlag from '../../../hooks/useFlag'; import useHistoryBack from '../../../hooks/useHistoryBack'; import useOldLang from '../../../hooks/useOldLang'; -import usePrevious from '../../../hooks/usePrevious'; +import usePreviousDeprecated from '../../../hooks/usePreviousDeprecated'; import ManageUsernames from '../../common/ManageUsernames'; import SafeLink from '../../common/SafeLink'; @@ -82,7 +82,7 @@ const ManageChatPrivacyType: FC = ({ const [isRevokeConfirmDialogOpen, openRevokeConfirmDialog, closeRevokeConfirmDialog] = useFlag(); const [isUsernameLostDialogOpen, openUsernameLostDialog, closeUsernameLostDialog] = useFlag(); - const previousIsUsernameAvailable = usePrevious(isUsernameAvailable); + const previousIsUsernameAvailable = usePreviousDeprecated(isUsernameAvailable); const renderingIsUsernameAvailable = isUsernameAvailable ?? previousIsUsernameAvailable; const canUpdate = isProfileFieldsTouched && Boolean( diff --git a/src/components/story/StorySlides.tsx b/src/components/story/StorySlides.tsx index a2c9594d5..97621ead3 100644 --- a/src/components/story/StorySlides.tsx +++ b/src/components/story/StorySlides.tsx @@ -32,7 +32,7 @@ import useAppLayout from '../../hooks/useAppLayout'; import useCurrentOrPrev from '../../hooks/useCurrentOrPrev'; import useHistoryBack from '../../hooks/useHistoryBack'; import useLastCallback from '../../hooks/useLastCallback'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import useWindowSize from '../../hooks/window/useWindowSize'; import useSlideSizes from './hooks/useSlideSizes'; @@ -91,7 +91,7 @@ function StorySlides({ const containerRef = useRef(null); const [renderingPeerId, setRenderingPeerId] = useState(currentPeerId); const [renderingStoryId, setRenderingStoryId] = useState(currentStoryId); - const prevPeerId = usePrevious(currentPeerId); + const prevPeerId = usePreviousDeprecated(currentPeerId); const renderingIsArchive = useCurrentOrPrev(isArchive, true); const renderingIsPrivate = useCurrentOrPrev(isPrivate, true); const renderingIsSinglePeer = useCurrentOrPrev(isSinglePeer, true); diff --git a/src/components/story/StoryViewer.tsx b/src/components/story/StoryViewer.tsx index b8d8f2495..15a5811f4 100644 --- a/src/components/story/StoryViewer.tsx +++ b/src/components/story/StoryViewer.tsx @@ -21,7 +21,7 @@ import { animateClosing, animateOpening } from './helpers/ghostAnimation'; import useFlag from '../../hooks/useFlag'; import { dispatchHeavyAnimationEvent } from '../../hooks/useHeavyAnimationCheck'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import { dispatchPriorityPlaybackEvent } from '../../hooks/usePriorityPlaybackCheck'; import useSlideSizes from './hooks/useSlideSizes'; import useStoryProps from './hooks/useStoryProps'; @@ -69,10 +69,10 @@ function StoryViewer({ const { bestImageData, thumbnail } = useStoryProps(story); const slideSizes = useSlideSizes(); - const isPrevOpen = usePrevious(isOpen); - const prevBestImageData = usePrevious(bestImageData); - const prevPeerId = usePrevious(peerId); - const prevOrigin = usePrevious(origin); + const isPrevOpen = usePreviousDeprecated(isOpen); + const prevBestImageData = usePreviousDeprecated(bestImageData); + const prevPeerId = usePreviousDeprecated(peerId); + const prevOrigin = usePreviousDeprecated(origin); const isGhostAnimation = Boolean(withAnimation && !shouldSkipHistoryAnimations); useEffect(() => { diff --git a/src/components/ui/ShowTransition.tsx b/src/components/ui/ShowTransition.tsx index 09559e937..0e7862a9e 100644 --- a/src/components/ui/ShowTransition.tsx +++ b/src/components/ui/ShowTransition.tsx @@ -3,7 +3,7 @@ import React, { useRef } from '../../lib/teact/teact'; import buildClassName from '../../util/buildClassName'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import useShowTransition from '../../hooks/useShowTransition'; type OwnProps = { @@ -33,8 +33,8 @@ const ShowTransition: FC = ({ style, ref, }) => { - const prevIsOpen = usePrevious(isOpen); - const prevChildren = usePrevious(children); + const prevIsOpen = usePreviousDeprecated(isOpen); + const prevChildren = usePreviousDeprecated(children); const fromChildrenRef = useRef(); const isFirstRender = prevIsOpen === undefined; const { diff --git a/src/components/ui/TabList.tsx b/src/components/ui/TabList.tsx index fb3c7bdf8..3db856ecb 100644 --- a/src/components/ui/TabList.tsx +++ b/src/components/ui/TabList.tsx @@ -10,7 +10,7 @@ import { IS_ANDROID, IS_IOS } from '../../util/windowEnvironment'; import useHorizontalScroll from '../../hooks/useHorizontalScroll'; import useOldLang from '../../hooks/useOldLang'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import Tab from './Tab'; @@ -45,7 +45,7 @@ const TabList: FC = ({ }) => { // eslint-disable-next-line no-null/no-null const containerRef = useRef(null); - const previousActiveTab = usePrevious(activeTab); + const previousActiveTab = usePreviousDeprecated(activeTab); useHorizontalScroll(containerRef, undefined, true); diff --git a/src/components/ui/Transition.tsx b/src/components/ui/Transition.tsx index 57bd17407..89553a770 100644 --- a/src/components/ui/Transition.tsx +++ b/src/components/ui/Transition.tsx @@ -15,7 +15,7 @@ import { allowSwipeControlForTransition } from '../../util/swipeController'; import useForceUpdate from '../../hooks/useForceUpdate'; import { dispatchHeavyAnimationEvent } from '../../hooks/useHeavyAnimationCheck'; -import usePrevious from '../../hooks/usePrevious'; +import usePreviousDeprecated from '../../hooks/usePreviousDeprecated'; import './Transition.scss'; @@ -98,7 +98,7 @@ function Transition({ } const rendersRef = useRef>({}); - const prevActiveKey = usePrevious(activeKey); + const prevActiveKey = usePreviousDeprecated(activeKey); const forceUpdate = useForceUpdate(); const isAnimatingRef = useRef(false); const isSwipeJustCancelledRef = useRef(false); diff --git a/src/hooks/useCurrentOrPrev.ts b/src/hooks/useCurrentOrPrev.ts index ee12bf2c8..5d35cb911 100644 --- a/src/hooks/useCurrentOrPrev.ts +++ b/src/hooks/useCurrentOrPrev.ts @@ -1,9 +1,9 @@ -import usePrevious from './usePrevious'; +import usePreviousDeprecated from './usePreviousDeprecated'; export default function useCurrentOrPrev( current: T, shouldSkipUndefined = false, shouldForceCurrent = false, ): T | undefined { - const prev = usePrevious(current, shouldSkipUndefined); + const prev = usePreviousDeprecated(current, shouldSkipUndefined); // eslint-disable-next-line no-null/no-null return shouldForceCurrent || (current !== null && current !== undefined) ? current : prev; diff --git a/src/hooks/useInfiniteScroll.ts b/src/hooks/useInfiniteScroll.ts index 2221ba7f0..8c2f3624b 100644 --- a/src/hooks/useInfiniteScroll.ts +++ b/src/hooks/useInfiniteScroll.ts @@ -5,7 +5,7 @@ import { LoadMoreDirection } from '../types'; import { areSortedArraysEqual } from '../util/iteratees'; import useForceUpdate from './useForceUpdate'; import useLastCallback from './useLastCallback'; -import usePrevious from './usePrevious'; +import usePreviousDeprecated from './usePreviousDeprecated'; type GetMore = (args: { direction: LoadMoreDirection }) => void; type LoadMoreBackwards = (args: { offsetId?: string | number }) => void; @@ -39,8 +39,8 @@ const useInfiniteScroll = ( requestParamsRef.current = {}; } - const prevListIds = usePrevious(listIds); - const prevIsDisabled = usePrevious(isDisabled); + const prevListIds = usePreviousDeprecated(listIds); + const prevIsDisabled = usePreviousDeprecated(isDisabled); if (listIds && !isDisabled && (listIds !== prevListIds || isDisabled !== prevIsDisabled)) { const { viewportIds, isOnTop } = currentStateRef.current || {}; const currentMiddleId = viewportIds && !isOnTop ? viewportIds[Math.round(viewportIds.length / 2)] : undefined; diff --git a/src/hooks/usePrevDuringAnimation.ts b/src/hooks/usePrevDuringAnimation.ts index d5040a7fd..a9237bf95 100644 --- a/src/hooks/usePrevDuringAnimation.ts +++ b/src/hooks/usePrevDuringAnimation.ts @@ -1,11 +1,11 @@ import { useRef } from '../lib/teact/teact'; import useForceUpdate from './useForceUpdate'; -import usePrevious from './usePrevious'; +import usePreviousDeprecated from './usePreviousDeprecated'; import useSyncEffect from './useSyncEffect'; export default function usePrevDuringAnimation(current: T, duration?: number): T { - const prev = usePrevious(current, true); + const prev = usePreviousDeprecated(current, true); const timeoutRef = useRef(); const forceUpdate = useForceUpdate(); // eslint-disable-next-line no-null/no-null diff --git a/src/hooks/usePrevious.ts b/src/hooks/usePrevious.ts index 6da28f0bd..a10b77d27 100644 --- a/src/hooks/usePrevious.ts +++ b/src/hooks/usePrevious.ts @@ -1,17 +1,15 @@ import { useRef } from '../lib/teact/teact'; -// Deprecated. Use `usePrevious2` instead -function usePrevious(next: T): T | undefined; -function usePrevious(next: T, shouldSkipUndefined: true): Exclude | undefined; -function usePrevious(next: T, shouldSkipUndefined?: boolean): Exclude | undefined; -function usePrevious(next: T, shouldSkipUndefined?: boolean) { - const ref = useRef(); - const { current } = ref; - if (!shouldSkipUndefined || next !== undefined) { - ref.current = next; +// This is not render-dependent and will never allow previous to match current +export default function usePrevious(current: T) { + const prevRef = useRef(); + const lastRef = useRef(); + + if (lastRef.current !== current) { + prevRef.current = lastRef.current; } - return current; -} + lastRef.current = current; -export default usePrevious; + return prevRef.current; +} diff --git a/src/hooks/usePrevious2.ts b/src/hooks/usePrevious2.ts deleted file mode 100644 index 996e25edc..000000000 --- a/src/hooks/usePrevious2.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { useRef } from '../lib/teact/teact'; - -// This is not render-dependent and will never allow previous to match current -export default function usePrevious2(current: T) { - const prevRef = useRef(); - const lastRef = useRef(); - - if (lastRef.current !== current) { - prevRef.current = lastRef.current; - } - - lastRef.current = current; - - return prevRef.current; -} diff --git a/src/hooks/usePreviousDeprecated.ts b/src/hooks/usePreviousDeprecated.ts new file mode 100644 index 000000000..a8c56cf8c --- /dev/null +++ b/src/hooks/usePreviousDeprecated.ts @@ -0,0 +1,20 @@ +import { useRef } from '../lib/teact/teact'; + +/** + * @deprecated + */ +function usePreviousDeprecated(next: T): T | undefined; +function usePreviousDeprecated(next: T, shouldSkipUndefined: true): Exclude | undefined; +// eslint-disable-next-line max-len +function usePreviousDeprecated(next: T, shouldSkipUndefined?: boolean): Exclude | undefined; +function usePreviousDeprecated(next: T, shouldSkipUndefined?: boolean) { + const ref = useRef(); + const { current } = ref; + if (!shouldSkipUndefined || next !== undefined) { + ref.current = next; + } + + return current; +} + +export default usePreviousDeprecated; diff --git a/src/hooks/useSyncEffect.ts b/src/hooks/useSyncEffect.ts index dc5153e3e..6a8437470 100644 --- a/src/hooks/useSyncEffect.ts +++ b/src/hooks/useSyncEffect.ts @@ -1,13 +1,13 @@ import { useRef } from '../lib/teact/teact'; import useEffectOnce from './useEffectOnce'; -import usePrevious from './usePrevious'; +import usePreviousDeprecated from './usePreviousDeprecated'; export default function useSyncEffect( effect: (args: T | readonly []) => NoneToVoidFunction | void, dependencies: T, ) { - const prevDeps = usePrevious(dependencies); + const prevDeps = usePreviousDeprecated(dependencies); const cleanupRef = useRef(); if (!prevDeps || dependencies.some((d, i) => d !== prevDeps[i])) {