Skip to content

Commit

Permalink
refactor(chore):3896-replace-lodash-debounce-to-useDebounce (#4814)
Browse files Browse the repository at this point in the history
Close: #3896 

## PR Details

Changed `lodash.debounce` to `useDebounce`.

Co-authored-by: VoitovychDM <[email protected]>
  • Loading branch information
voytovichdm and VoitovychDM authored Apr 5, 2024
1 parent 7774ef6 commit a95972f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useMemo, useRef, useState } from 'react';
import styled from '@emotion/styled';
import { isNonEmptyString } from '@sniptt/guards';
import debounce from 'lodash.debounce';
import { useDebouncedCallback } from 'use-debounce';

import { MultipleObjectRecordOnClickOutsideEffect } from '@/object-record/relation-picker/components/MultipleObjectRecordOnClickOutsideEffect';
import { MultipleObjectRecordSelectItem } from '@/object-record/relation-picker/components/MultipleObjectRecordSelectItem';
Expand Down Expand Up @@ -83,7 +83,7 @@ export const MultipleObjectRecordSelect = ({
}
}, [selectedObjectRecordsForSelect, loading]);

const debouncedSetSearchFilter = debounce(setSearchFilter, 100, {
const debouncedSetSearchFilter = useDebouncedCallback(setSearchFilter, 100, {
leading: true,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import debounce from 'lodash.debounce';
import { useDebouncedCallback } from 'use-debounce';

import { useRelationPicker } from '@/object-record/relation-picker/hooks/useRelationPicker';

Expand All @@ -14,7 +14,7 @@ export const useEntitySelectSearch = ({
setRelationPickerSearchFilter,
} = useRelationPicker({ relationPickerScopeId });

const debouncedSetSearchFilter = debounce(
const debouncedSetSearchFilter = useDebouncedCallback(
setRelationPickerSearchFilter,
100,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from 'react';
import styled from '@emotion/styled';
import debounce from 'lodash.debounce';
import { useRecoilState, useRecoilValue } from 'recoil';
import { useDebouncedCallback } from 'use-debounce';

import { currentUserState } from '@/auth/states/currentUserState';
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState';
Expand Down Expand Up @@ -46,7 +46,7 @@ export const NameFields = ({
});

// TODO: Enhance this with react-web-hook-form (https://www.react-hook-form.com)
const debouncedUpdate = debounce(async () => {
const debouncedUpdate = useDebouncedCallback(async () => {
onFirstNameUpdate?.(firstName);
onLastNameUpdate?.(lastName);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useState } from 'react';
import styled from '@emotion/styled';
import debounce from 'lodash.debounce';
import { useRecoilValue } from 'recoil';
import { useDebouncedCallback } from 'use-debounce';

import { currentWorkspaceState } from '@/auth/states/currentWorkspaceState';
import { TextInput } from '@/ui/input/components/TextInput';
Expand Down Expand Up @@ -38,7 +38,7 @@ export const NameField = ({
// TODO: Enhance this with react-web-hook-form (https://www.react-hook-form.com)
// eslint-disable-next-line react-hooks/exhaustive-deps
const debouncedUpdate = useCallback(
debounce(async (name: string) => {
useDebouncedCallback(async (name: string) => {
if (isDefined(onNameUpdate)) {
onNameUpdate(displayName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
size,
useFloating,
} from '@floating-ui/react';
import debounce from 'lodash.debounce';
import { ReadonlyDeep } from 'type-fest';
import { useDebouncedCallback } from 'use-debounce';

import { SelectOption } from '@/spreadsheet-import/types';
import { AppTooltip } from '@/ui/display/tooltip/AppTooltip';
Expand Down Expand Up @@ -72,9 +72,13 @@ export const MatchColumnSelect = ({
[initialOptions],
);

const debouncedHandleSearchFilter = debounce(handleSearchFilterChange, 100, {
leading: true,
});
const debouncedHandleSearchFilter = useDebouncedCallback(
handleSearchFilterChange,
100,
{
leading: true,
},
);

const handleFilterChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const value = event.currentTarget.value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactNode, useState } from 'react';
import styled from '@emotion/styled';
import { AnimatePresence, LayoutGroup } from 'framer-motion';
import debounce from 'lodash.debounce';
import { useDebouncedCallback } from 'use-debounce';

import {
H1Title,
Expand Down Expand Up @@ -78,7 +78,7 @@ export const ConfirmationModal = ({
isValueMatchingInput(confirmationValue, value);
};

const isValueMatchingInput = debounce(
const isValueMatchingInput = useDebouncedCallback(
(value?: string, inputValue?: string) => {
setIsValidValue(Boolean(value && inputValue && value === inputValue));
},
Expand Down

0 comments on commit a95972f

Please sign in to comment.