Memoize context values
This commit is contained in:
parent
1111fd00a1
commit
e542fcb8aa
4 changed files with 36 additions and 8 deletions
|
@ -87,9 +87,18 @@ const AlbumListRoute = () => {
|
||||||
[albumListFilter, customFilters, handlePlayQueueAdd, itemCount, server],
|
[albumListFilter, customFilters, handlePlayQueueAdd, itemCount, server],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const providerValue = useMemo(() => {
|
||||||
|
return {
|
||||||
|
customFilters,
|
||||||
|
handlePlay,
|
||||||
|
id: albumArtistId ?? undefined,
|
||||||
|
pageKey,
|
||||||
|
};
|
||||||
|
}, [albumArtistId, customFilters, handlePlay, pageKey]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatedPage>
|
<AnimatedPage>
|
||||||
<ListContext.Provider value={{ customFilters, handlePlay, id: albumArtistId, pageKey }}>
|
<ListContext.Provider value={providerValue}>
|
||||||
<AlbumListHeader
|
<AlbumListHeader
|
||||||
gridRef={gridRef}
|
gridRef={gridRef}
|
||||||
itemCount={itemCount}
|
itemCount={itemCount}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { useRef } from 'react';
|
import { useMemo, useRef } from 'react';
|
||||||
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
||||||
import { useParams } from 'react-router';
|
import { useParams } from 'react-router';
|
||||||
import { AlbumArtistDetailTopSongsListContent } from '/@/renderer/features/artists/components/album-artist-detail-top-songs-list-content';
|
import { AlbumArtistDetailTopSongsListContent } from '/@/renderer/features/artists/components/album-artist-detail-top-songs-list-content';
|
||||||
|
@ -29,11 +29,16 @@ const AlbumArtistDetailTopSongsListRoute = () => {
|
||||||
|
|
||||||
const itemCount = topSongsQuery?.data?.items?.length || 0;
|
const itemCount = topSongsQuery?.data?.items?.length || 0;
|
||||||
|
|
||||||
if (detailQuery.isLoading || topSongsQuery?.isLoading) return null;
|
const providerValue = useMemo(() => {
|
||||||
|
return {
|
||||||
|
id: albumArtistId,
|
||||||
|
pageKey,
|
||||||
|
};
|
||||||
|
}, [albumArtistId, pageKey]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatedPage>
|
<AnimatedPage>
|
||||||
<ListContext.Provider value={{ id: albumArtistId, pageKey }}>
|
<ListContext.Provider value={providerValue}>
|
||||||
<AlbumArtistDetailTopSongsListHeader
|
<AlbumArtistDetailTopSongsListHeader
|
||||||
data={topSongsQuery?.data?.items || []}
|
data={topSongsQuery?.data?.items || []}
|
||||||
itemCount={itemCount}
|
itemCount={itemCount}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
||||||
import { useRef } from 'react';
|
import { useMemo, useRef } from 'react';
|
||||||
import { useCurrentServer } from '../../../store/auth.store';
|
import { useCurrentServer } from '../../../store/auth.store';
|
||||||
import { useListFilterByKey } from '../../../store/list.store';
|
import { useListFilterByKey } from '../../../store/list.store';
|
||||||
import { LibraryItem } from '/@/renderer/api/types';
|
import { LibraryItem } from '/@/renderer/api/types';
|
||||||
|
@ -36,9 +36,16 @@ const AlbumArtistListRoute = () => {
|
||||||
? undefined
|
? undefined
|
||||||
: itemCountCheck.data?.totalRecordCount;
|
: itemCountCheck.data?.totalRecordCount;
|
||||||
|
|
||||||
|
const providerValue = useMemo(() => {
|
||||||
|
return {
|
||||||
|
id: undefined,
|
||||||
|
pageKey,
|
||||||
|
};
|
||||||
|
}, [pageKey]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatedPage>
|
<AnimatedPage>
|
||||||
<ListContext.Provider value={{ id: undefined, pageKey }}>
|
<ListContext.Provider value={providerValue}>
|
||||||
<AlbumArtistListHeader
|
<AlbumArtistListHeader
|
||||||
gridRef={gridRef}
|
gridRef={gridRef}
|
||||||
itemCount={itemCount}
|
itemCount={itemCount}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
||||||
import { useRef } from 'react';
|
import { useMemo, useRef } from 'react';
|
||||||
import { useParams } from 'react-router';
|
import { useParams } from 'react-router';
|
||||||
import { PlaylistListSort, SortOrder } from '/@/renderer/api/types';
|
import { PlaylistListSort, SortOrder } from '/@/renderer/api/types';
|
||||||
import { VirtualInfiniteGridRef } from '/@/renderer/components/virtual-grid';
|
import { VirtualInfiniteGridRef } from '/@/renderer/components/virtual-grid';
|
||||||
|
@ -38,9 +38,16 @@ const PlaylistListRoute = () => {
|
||||||
? undefined
|
? undefined
|
||||||
: itemCountCheck.data?.totalRecordCount;
|
: itemCountCheck.data?.totalRecordCount;
|
||||||
|
|
||||||
|
const providerValue = useMemo(() => {
|
||||||
|
return {
|
||||||
|
id: playlistId,
|
||||||
|
pageKey,
|
||||||
|
};
|
||||||
|
}, [playlistId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatedPage>
|
<AnimatedPage>
|
||||||
<ListContext.Provider value={{ id: playlistId, pageKey }}>
|
<ListContext.Provider value={providerValue}>
|
||||||
<PlaylistListHeader
|
<PlaylistListHeader
|
||||||
gridRef={gridRef}
|
gridRef={gridRef}
|
||||||
itemCount={itemCount}
|
itemCount={itemCount}
|
||||||
|
|
Reference in a new issue