({
- range: [h, 0],
- domain: [minPrice - maxSpread / 2, maxPrice + maxSpread / 2],
- });
-
return (
<>
@@ -266,7 +265,7 @@ export const CandlesticksTooltip = ({
const ac = new AbortController();
void getBlockDate(data.height, ac.signal).then(setBlockDate);
return () => ac.abort('Abort tooltip date query');
- }, [data]);
+ }, [data, getBlockDate]);
const endBase = endMetadata.denomUnits.filter(d => !d.exponent)[0]!;
const startBase = startMetadata.denomUnits.filter(d => !d.exponent)[0]!;
diff --git a/packages/ui/components/ui/tx/index.tsx b/packages/ui/components/ui/tx/index.tsx
index ab7bc2ee85..0bcb2d93b5 100644
--- a/packages/ui/components/ui/tx/index.tsx
+++ b/packages/ui/components/ui/tx/index.tsx
@@ -49,7 +49,7 @@ const useFeeMetadata = (txv: TransactionView, getMetadata: MetadataFetchFn) => {
setIsLoading(false);
})
.catch((e: unknown) => setError(e));
- }, [txv, getMetadata, setFeeValueView]);
+ }, [txv, getMetadata, setFeeValueView, amount]);
return { feeValueView, isLoading, error };
};
diff --git a/packages/zquery/src/get-use-hook.ts b/packages/zquery/src/get-use-hook.ts
index be0f9c0e19..5b0a0f488b 100644
--- a/packages/zquery/src/get-use-hook.ts
+++ b/packages/zquery/src/get-use-hook.ts
@@ -1,4 +1,4 @@
-import { useEffect, useRef } from 'react';
+import { useEffect, useRef, useState } from 'react';
import {
AbridgedZQueryState,
CreateZQueryStreamingProps,
@@ -7,6 +7,9 @@ import {
ZQueryState,
} from './types.js';
+const shallowCompareArrays = (a: unknown[], b: unknown[]): boolean =>
+ a.every((item, index) => item === b[index]) && a.length === b.length;
+
/**
* Returns a hook that can be used via `use[Name]()` to access the ZQuery state.
*/
@@ -72,29 +75,35 @@ export const getUseHook = <
) => {
const useStore = props.getUseStore();
+ // We want to use a custom comparator to see if `fetchArgs` changed.
+ // `useMemo()` does not support custom comparators, so we'll roll it ourself
+ // using a combination of `useState` and `useEffect`.
+ const [fetchArgsMemo, setFetchArgsMemo] = useState(fetchArgs);
useEffect(() => {
- const fetch = props.get(useStore.getState())._zQueryInternal.fetch;
+ if (!shallowCompareArrays(fetchArgs, fetchArgsMemo)) {
+ setFetchArgsMemo(fetchArgs);
+ }
+ }, [fetchArgs, fetchArgsMemo]);
- {
- const newReferenceCount = incrementReferenceCounter();
+ useEffect(() => {
+ const fetch = props.get(useStore.getState())._zQueryInternal.fetch;
- if (newReferenceCount === 1) {
- setAbortController(new AbortController());
- void fetch(...fetchArgs);
- }
+ const incrementedReferenceCount = incrementReferenceCounter();
+ if (incrementedReferenceCount === 1) {
+ setAbortController(new AbortController());
+ void fetch(...fetchArgsMemo);
}
const onUnmount = () => {
- const newReferenceCount = decrementReferenceCounter();
-
- if (newReferenceCount === 0) {
+ const decrementedReferenceCount = decrementReferenceCounter();
+ if (decrementedReferenceCount === 0) {
props.get(useStore.getState())._zQueryInternal.abortController?.abort();
setAbortController(undefined);
}
};
return onUnmount;
- }, [fetch]);
+ }, [fetchArgsMemo, useStore]);
const prevState = useRef | undefined>();
const prevSelectedState = useRef<