GoodDollar / GoodWeb3-Mono

mono repo with GoodDollar's web3 UI components and SDK
https://gooddollar-storybook.vercel.app
0 stars 1 forks source link

add throttle as generic refresh hook #76

Closed L03TJ3 closed 1 year ago

L03TJ3 commented 1 year ago
          this looks like some effect - I'd suggest to wrap it onto useEffect with [latest] dep

e.g.

const refreshOrNever = useRefreshOrNever(refresh);
const [refreshValue, setRefreshValue] = useState(refreshOrNever);

useEffect(() => {
  // if we connected wallet or did a tx then force a refresh
  const forceRefresh = latest && latest.type !== "transactionStarted" && latest?.submittedAt > lastNotification.current;

  if (forceRefresh) {
    lastNotification.current = latest?.submittedAt;
  }

  setRefreshValue(forceRefresh ? 1 : refreshOrNever);
}, [refreshOrNever, latest, setRefreshValue]);

 // in useCalls
{ refresh: refreshValue }

_Originally posted by @johnsmith-gooddollar in https://github.com/GoodDollar/GoodWeb3-Mono/pull/74#discussion_r1133861076_