Memoise ListView context (#31668)
* Update npm non-major dependencies * Make types happier Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Memoise ListView context Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Discard changes to yarn.lock --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
parent
a5af6cf23f
commit
cb7e8f4910
@@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
|
|||||||
Please see LICENSE files in the repository root for full details.
|
Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useRef, type JSX, useCallback, useEffect, useState } from "react";
|
import React, { useRef, type JSX, useCallback, useEffect, useState, useMemo } from "react";
|
||||||
import { type VirtuosoHandle, type ListRange, Virtuoso, type VirtuosoProps } from "react-virtuoso";
|
import { type VirtuosoHandle, type ListRange, Virtuoso, type VirtuosoProps } from "react-virtuoso";
|
||||||
|
|
||||||
import { isModifiedKeyEvent, Key } from "../../Keyboard";
|
import { isModifiedKeyEvent, Key } from "../../Keyboard";
|
||||||
@@ -293,11 +293,14 @@ export function ListView<Item, Context = any>(props: IListViewProps<Item, Contex
|
|||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const listContext: ListContext<Context> = {
|
const listContext: ListContext<Context> = useMemo(
|
||||||
tabIndexKey: tabIndexKey,
|
() => ({
|
||||||
focused: isFocused,
|
tabIndexKey: tabIndexKey,
|
||||||
context: props.context || ({} as Context),
|
focused: isFocused,
|
||||||
};
|
context: props.context || ({} as Context),
|
||||||
|
}),
|
||||||
|
[tabIndexKey, isFocused, props.context],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Virtuoso
|
<Virtuoso
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* Please see LICENSE files in the repository root for full details.
|
* Please see LICENSE files in the repository root for full details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React, { useCallback, useRef, type JSX } from "react";
|
import React, { useCallback, useRef, type JSX, useMemo } from "react";
|
||||||
import { type Room } from "matrix-js-sdk/src/matrix";
|
import { type Room } from "matrix-js-sdk/src/matrix";
|
||||||
import { isEqual } from "lodash";
|
import { isEqual } from "lodash";
|
||||||
|
|
||||||
@@ -112,10 +112,14 @@ export function RoomList({ vm: { roomsResult, activeIndex } }: RoomListProps): J
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
const context = useMemo<Context>(
|
||||||
|
() => ({ spaceId: roomsResult.spaceId, filterKeys: roomsResult.filterKeys }),
|
||||||
|
[roomsResult.spaceId, roomsResult.filterKeys],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ListView
|
<ListView
|
||||||
context={{ spaceId: roomsResult.spaceId, filterKeys: roomsResult.filterKeys }}
|
context={context}
|
||||||
scrollIntoViewOnChange={scrollIntoViewOnChange}
|
scrollIntoViewOnChange={scrollIntoViewOnChange}
|
||||||
initialTopMostItemIndex={activeIndex}
|
initialTopMostItemIndex={activeIndex}
|
||||||
data-testid="room-list"
|
data-testid="room-list"
|
||||||
|
|||||||
Reference in New Issue
Block a user