Skip to content

Commit

Permalink
Use memo to avoid rebuilding the list of options
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Feb 28, 2025
1 parent a6c408a commit 49affb3
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions packages/block-library/src/query/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,43 +203,45 @@ export function useOrderByOptions( postType ) {
[ postType ]
);

const orderByOptions = [
{
label: __( 'Newest to oldest' ),
value: 'date/desc',
},
{
label: __( 'Oldest to newest' ),
value: 'date/asc',
},
{
/* translators: Label for ordering posts by title in ascending order. */
label: __( 'A → Z' ),
value: 'title/asc',
},
{
/* translators: Label for ordering posts by title in descending order. */
label: __( 'Z → A' ),
value: 'title/desc',
},
];

if ( supportsCustomOrder ) {
orderByOptions.push(
return useMemo( () => {
const orderByOptions = [
{
/* translators: Label for ordering posts by ascending menu order. */
label: __( 'Ascending by order' ),
value: 'menu_order/asc',
label: __( 'Newest to oldest' ),
value: 'date/desc',
},
{
/* translators: Label for ordering posts by descending menu order. */
label: __( 'Descending by order' ),
value: 'menu_order/desc',
}
);
}
label: __( 'Oldest to newest' ),
value: 'date/asc',
},
{
/* translators: Label for ordering posts by title in ascending order. */
label: __( 'A → Z' ),
value: 'title/asc',
},
{
/* translators: Label for ordering posts by title in descending order. */
label: __( 'Z → A' ),
value: 'title/desc',
},
];

if ( supportsCustomOrder ) {
orderByOptions.push(
{
/* translators: Label for ordering posts by ascending menu order. */
label: __( 'Ascending by order' ),
value: 'menu_order/asc',
},
{
/* translators: Label for ordering posts by descending menu order. */
label: __( 'Descending by order' ),
value: 'menu_order/desc',
}
);
}

return orderByOptions;
return orderByOptions;
}, [ supportsCustomOrder ] );
}

/**
Expand Down

0 comments on commit 49affb3

Please sign in to comment.