diff --git a/components/cart/CartItem/CartItem.tsx b/components/cart/CartItem/CartItem.tsx index a59024e06..4453e0c08 100644 --- a/components/cart/CartItem/CartItem.tsx +++ b/components/cart/CartItem/CartItem.tsx @@ -70,6 +70,9 @@ const CartItem = ({ if (item.quantity !== Number(quantity)) { setQuantity(item.quantity) } + // TODO: currently not including quantity in deps is intended, but we should + // do this differently as it could break easily + // eslint-disable-next-line react-hooks/exhaustive-deps }, [item.quantity]) return ( diff --git a/components/common/Footer/Footer.tsx b/components/common/Footer/Footer.tsx index 04b80404e..8cfcc9666 100644 --- a/components/common/Footer/Footer.tsx +++ b/components/common/Footer/Footer.tsx @@ -73,7 +73,7 @@ const Footer: FC = ({ className, pages }) => {
Created by ( ) const dynamicProps = { - loading: () => , + loading: Loading, } const SignUpView = dynamic( diff --git a/components/common/Searchbar/Searchbar.tsx b/components/common/Searchbar/Searchbar.tsx index 0fc276d02..ee20a3ade 100644 --- a/components/common/Searchbar/Searchbar.tsx +++ b/components/common/Searchbar/Searchbar.tsx @@ -1,4 +1,4 @@ -import { FC, InputHTMLAttributes, useEffect, useMemo } from 'react' +import { FC, memo, useEffect } from 'react' import cn from 'classnames' import s from './Searchbar.module.css' import { useRouter } from 'next/router' @@ -13,7 +13,7 @@ const Searchbar: FC = ({ className, id = 'search' }) => { useEffect(() => { router.prefetch('/search') - }, []) + }, [router]) const handleKeyUp = (e: React.KeyboardEvent) => { e.preventDefault() @@ -32,32 +32,29 @@ const Searchbar: FC = ({ className, id = 'search' }) => { } } - return useMemo( - () => ( -
- - -
- - - -
+ return ( +
+ + +
+ + +
- ), - [] +
) } -export default Searchbar +export default memo(Searchbar) diff --git a/components/product/ProductOptions/ProductOptions.tsx b/components/product/ProductOptions/ProductOptions.tsx index 9261406bc..456df4bfc 100644 --- a/components/product/ProductOptions/ProductOptions.tsx +++ b/components/product/ProductOptions/ProductOptions.tsx @@ -1,50 +1,52 @@ +import { memo } from 'react' import { Swatch } from '@components/product' import type { ProductOption } from '@commerce/types/product' import { SelectedOptions } from '../helpers' -import React from 'react' + interface ProductOptionsProps { options: ProductOption[] selectedOptions: SelectedOptions setSelectedOptions: React.Dispatch> } -const ProductOptions: React.FC = React.memo( - ({ options, selectedOptions, setSelectedOptions }) => { - return ( -
- {options.map((opt) => ( -
-

- {opt.displayName} -

-
- {opt.values.map((v, i: number) => { - const active = selectedOptions[opt.displayName.toLowerCase()] - return ( - { - setSelectedOptions((selectedOptions) => { - return { - ...selectedOptions, - [opt.displayName.toLowerCase()]: - v.label.toLowerCase(), - } - }) - }} - /> - ) - })} -
+const ProductOptions: React.FC = ({ + options, + selectedOptions, + setSelectedOptions, +}) => { + return ( +
+ {options.map((opt) => ( +
+

+ {opt.displayName} +

+
+ {opt.values.map((v, i: number) => { + const active = selectedOptions[opt.displayName.toLowerCase()] + return ( + { + setSelectedOptions((selectedOptions) => { + return { + ...selectedOptions, + [opt.displayName.toLowerCase()]: v.label.toLowerCase(), + } + }) + }} + /> + ) + })}
- ))} -
- ) - } -) +
+ ))} +
+ ) +} -export default ProductOptions +export default memo(ProductOptions) diff --git a/components/product/ProductSidebar/ProductSidebar.tsx b/components/product/ProductSidebar/ProductSidebar.tsx index fe8a71aa5..fd1ef1e0a 100644 --- a/components/product/ProductSidebar/ProductSidebar.tsx +++ b/components/product/ProductSidebar/ProductSidebar.tsx @@ -23,7 +23,7 @@ const ProductSidebar: FC = ({ product, className }) => { useEffect(() => { selectDefaultOptionFromProduct(product, setSelectedOptions) - }, []) + }, [product]) const variant = getProductVariant(product, selectedOptions) const addToCart = async () => { diff --git a/components/product/ProductSlider/ProductSlider.tsx b/components/product/ProductSlider/ProductSlider.tsx index 8c3441906..537a12a46 100644 --- a/components/product/ProductSlider/ProductSlider.tsx +++ b/components/product/ProductSlider/ProductSlider.tsx @@ -66,17 +66,13 @@ const ProductSlider: React.FC = ({ event.preventDefault() } - sliderContainerRef.current!.addEventListener( - 'touchstart', - preventNavigation - ) + const slider = sliderContainerRef.current! + + slider.addEventListener('touchstart', preventNavigation) return () => { - if (sliderContainerRef.current) { - sliderContainerRef.current!.removeEventListener( - 'touchstart', - preventNavigation - ) + if (slider) { + slider.removeEventListener('touchstart', preventNavigation) } } }, []) diff --git a/components/product/ProductSliderControl/ProductSliderControl.tsx b/components/product/ProductSliderControl/ProductSliderControl.tsx index 4e767b5db..5525c58de 100644 --- a/components/product/ProductSliderControl/ProductSliderControl.tsx +++ b/components/product/ProductSliderControl/ProductSliderControl.tsx @@ -1,31 +1,30 @@ +import { FC, MouseEventHandler, memo } from 'react' import cn from 'classnames' -import React from 'react' import s from './ProductSliderControl.module.css' import { ArrowLeft, ArrowRight } from '@components/icons' interface ProductSliderControl { - onPrev: React.MouseEventHandler - onNext: React.MouseEventHandler + onPrev: MouseEventHandler + onNext: MouseEventHandler } -const ProductSliderControl: React.FC = React.memo( - ({ onPrev, onNext }) => ( -
- - -
- ) +const ProductSliderControl: FC = ({ onPrev, onNext }) => ( +
+ + +
) -export default ProductSliderControl + +export default memo(ProductSliderControl) diff --git a/components/search.tsx b/components/search.tsx index 10fd5df68..e7663b5e5 100644 --- a/components/search.tsx +++ b/components/search.tsx @@ -7,7 +7,7 @@ import { useRouter } from 'next/router' import { Layout } from '@components/common' import { ProductCard } from '@components/product' import type { Product } from '@commerce/types/product' -import { Container, Grid, Skeleton } from '@components/ui' +import { Container, Skeleton } from '@components/ui' import useSearch from '@framework/product/use-search' diff --git a/components/ui/Modal/Modal.tsx b/components/ui/Modal/Modal.tsx index bb42b3d1b..de45c2814 100644 --- a/components/ui/Modal/Modal.tsx +++ b/components/ui/Modal/Modal.tsx @@ -27,13 +27,15 @@ const Modal: FC = ({ children, onClose }) => { ) useEffect(() => { - if (ref.current) { - disableBodyScroll(ref.current, { reserveScrollBarGap: true }) + const modal = ref.current + + if (modal) { + disableBodyScroll(modal, { reserveScrollBarGap: true }) window.addEventListener('keydown', handleKey) } return () => { - if (ref && ref.current) { - enableBodyScroll(ref.current) + if (modal) { + enableBodyScroll(modal) } clearAllBodyScrollLocks() window.removeEventListener('keydown', handleKey) diff --git a/components/ui/Rating/Rating.tsx b/components/ui/Rating/Rating.tsx index 259e642ea..e3a9c6d12 100644 --- a/components/ui/Rating/Rating.tsx +++ b/components/ui/Rating/Rating.tsx @@ -1,4 +1,4 @@ -import React, { FC } from 'react' +import { FC, memo } from 'react' import rangeMap from '@lib/range-map' import { Star } from '@components/icons' import cn from 'classnames' @@ -7,21 +7,19 @@ export interface RatingProps { value: number } -const Quantity: React.FC = React.memo(({ value = 5 }) => { - return ( -
- {rangeMap(5, (i) => ( - = Math.floor(value), - })} - > - - - ))} -
- ) -}) +const Quantity: FC = ({ value = 5 }) => ( +
+ {rangeMap(5, (i) => ( + = Math.floor(value), + })} + > + + + ))} +
+) -export default Quantity +export default memo(Quantity) diff --git a/components/ui/Sidebar/Sidebar.tsx b/components/ui/Sidebar/Sidebar.tsx index ce0eeefe2..700bb681a 100644 --- a/components/ui/Sidebar/Sidebar.tsx +++ b/components/ui/Sidebar/Sidebar.tsx @@ -16,13 +16,14 @@ const Sidebar: FC = ({ children, onClose }) => { const ref = useRef() as React.MutableRefObject useEffect(() => { - if (ref.current) { - disableBodyScroll(ref.current, { reserveScrollBarGap: true }) + const sidebar = ref.current + + if (sidebar) { + disableBodyScroll(sidebar, { reserveScrollBarGap: true }) } + return () => { - if (ref && ref.current) { - enableBodyScroll(ref.current) - } + if (sidebar) enableBodyScroll(sidebar) clearAllBodyScrollLocks() } }, []) diff --git a/lib/search.tsx b/lib/search.tsx index 87b42db36..eaeaf66fc 100644 --- a/lib/search.tsx +++ b/lib/search.tsx @@ -18,10 +18,10 @@ export function useSearchMeta(asPath: string) { c = parts[4] } - setPathname(path) + if (path !== pathname) setPathname(path) if (c !== category) setCategory(c) if (b !== brand) setBrand(b) - }, [asPath]) + }, [asPath, pathname, category, brand]) return { pathname, category, brand } }