Skip to content

Commit

Permalink
fix(llm): 🐛 debounce memo tag changes (#8632)
Browse files Browse the repository at this point in the history
fix(llm): debounce memo tag changes
  • Loading branch information
thesan authored Dec 6, 2024
1 parent 64aae3b commit c7335b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-hats-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"live-mobile": minor
---

Debounce memo tag changes
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FC, useCallback, useState } from "react";
import debounce from "lodash/debounce";
import { FC, useCallback, useMemo, useState } from "react";

import { useFeature } from "@ledgerhq/live-common/featureFlags/index";
import { Transaction } from "@ledgerhq/live-common/generated/types";
Expand All @@ -18,14 +19,20 @@ export const useMemoTagInput = (

const [isEmpty, setIsEmpty] = useState(true);
const [error, setError] = useState<Error | undefined>();
const debouncedUpdateTransaction = useMemo(
() => debounce(updateTransaction, DEBOUNCE_DELAY),
[updateTransaction],
);
const handleChange = useCallback<MemoTagInputProps["onChange"]>(
({ patch, value, error }) => {
setIsEmpty(!value);
setError(error);
updateTransaction(patch);
debouncedUpdateTransaction(patch);
},
[updateTransaction],
[debouncedUpdateTransaction],
);

return Input && { Input, isEmpty, error, handleChange };
};

const DEBOUNCE_DELAY = 300;

0 comments on commit c7335b2

Please sign in to comment.