From be2c60d3f3a518909f3eef93af6f31f9e408e4ce Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Sun, 25 Sep 2022 16:43:53 -0700 Subject: [PATCH] Fix some rendering issues on contract page (#933) * Memoize calculating sale amount on your bets list * Don't re-render more than necessary with `useIsMobile` hook * Use `useIsMobile` hook in `AmountInput` --- web/components/amount-input.tsx | 5 ++--- web/components/bets-list.tsx | 22 ++++++++++++++-------- web/hooks/use-is-mobile.ts | 16 +++++++++++----- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/web/components/amount-input.tsx b/web/components/amount-input.tsx index 2ad745a8..76581d9e 100644 --- a/web/components/amount-input.tsx +++ b/web/components/amount-input.tsx @@ -5,7 +5,7 @@ import { formatMoney } from 'common/util/format' import { Col } from './layout/col' import { SiteLink } from './site-link' import { ENV_CONFIG } from 'common/envs/constants' -import { useWindowSize } from 'web/hooks/use-window-size' +import { useIsMobile } from 'web/hooks/use-is-mobile' export function AmountInput(props: { amount: number | undefined @@ -34,8 +34,7 @@ export function AmountInput(props: { const isInvalid = !str || isNaN(amount) onChange(isInvalid ? undefined : amount) } - const { width } = useWindowSize() - const isMobile = (width ?? 0) < 768 + const isMobile = useIsMobile(768) return (