Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Memoize query variables

dominik-zeglen4e08a3f93b73
diff --git a/saleor/static/dashboard-next/orders/views/OrderList/OrderList.tsx b/saleor/static/dashboard-next/orders/views/OrderList/OrderList.tsx
index 3c8991eef4..8b5873b8b5 100644
--- a/saleor/static/dashboard-next/orders/views/OrderList/OrderList.tsx
+++ b/saleor/static/dashboard-next/orders/views/OrderList/OrderList.tsx
@@ -132,16 +132,18 @@ export const OrderList: React.StatelessComponent<OrderListProps> = ({
navigate(orderUrl(data.draftOrderCreate.order.id));
};
+ const queryVariables = React.useMemo(
+ () => ({
+ ...paginationState,
+ filter: getFilterVariables(params)
+ }),
+ [params]
+ );
+
return (
<TypedOrderDraftCreateMutation onCompleted={handleCreateOrderCreateSuccess}>
{createOrder => (
- <TypedOrderListQuery
- displayLoader
- variables={{
- ...paginationState,
- filter: getFilterVariables(params)
- }}
- >
+ <TypedOrderListQuery displayLoader variables={queryVariables}>
{({ data, loading, refetch }) => {
const { loadNextPage, loadPreviousPage, pageInfo } = paginate(
maybe(() => data.orders.pageInfo),
diff --git a/saleor/static/dashboard-next/products/views/ProductList/ProductList.tsx b/saleor/static/dashboard-next/products/views/ProductList/ProductList.tsx
index 8ef1de90a8..9db1a2d00a 100644
--- a/saleor/static/dashboard-next/products/views/ProductList/ProductList.tsx
+++ b/saleor/static/dashboard-next/products/views/ProductList/ProductList.tsx
@@ -128,15 +128,16 @@ export const ProductList: React.StatelessComponent<ProductListProps> = ({
const paginationState = createPaginationState(PAGINATE_BY, params);
const currencySymbol = maybe(() => shop.defaultCurrency, "USD");
+ const queryVariables = React.useMemo(
+ () => ({
+ ...paginationState,
+ filter: getFilterVariables(params)
+ }),
+ [params]
+ );
return (
- <TypedProductListQuery
- displayLoader
- variables={{
- ...paginationState,
- filter: getFilterVariables(params)
- }}
- >
+ <TypedProductListQuery displayLoader variables={queryVariables}>
{({ data, loading, refetch }) => {
const { loadNextPage, loadPreviousPage, pageInfo } = paginate(
maybe(() => data.products.pageInfo),