Skip to content

Commit

Permalink
(fix) memoize price data
Browse files Browse the repository at this point in the history
  • Loading branch information
usamaidrsk committed Oct 17, 2024
1 parent 03fff2c commit d94e5b8
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useMemo } from 'react';
import { useOrderStockInfo } from '../hooks/useOrderStockInfo';
import { CheckmarkFilled, CloseFilled } from '@carbon/react/icons';
import styles from './order-stock-details.scss';
Expand All @@ -13,12 +13,18 @@ const OrderStockDetailsComponent: React.FC<OrderStockDetailsComponentProps> = ({
const { t } = useTranslation();
const { data: stockData, isLoading } = useOrderStockInfo(orderItemUuid);

const isInStock = useMemo(() => {
if (!stockData || stockData.entry.length === 0) {
return false;
}
const resource = stockData.entry[0]?.resource;
return resource.status === 'active' && resource.netContent?.value > 0;
}, [stockData]);

if (isLoading || !stockData) {
return <SkeletonText width="100px" />;
}

const isInStock = stockData.entry[0]?.resource.status === 'active';

return (
<div>
{isInStock ? (
Expand Down

0 comments on commit d94e5b8

Please sign in to comment.