Skip to content

Commit

Permalink
Use memo for filteredModels
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Oct 9, 2024
1 parent 4acf346 commit 2c8d6e9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/screens/home/displays/DisplayGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Link } from 'react-router-dom';
import { Map } from 'immutable';
import { motion } from 'framer-motion';
import { displayLayoutId } from '@luna/constants/LayoutId';
import { useMemo } from 'react';

export interface DisplayGridProps {
userModels: Map<string, UserModel>;
Expand All @@ -18,11 +19,15 @@ export function DisplayGrid({
displayWidth,
}: DisplayGridProps) {
// Filter the models case-insensitively by the search query
const filteredModels = [...userModels.entries()]
.filter(([username]) =>
username.toLowerCase().includes(searchQuery.toLowerCase())
)
.sort(([u1], [u2]) => u1.localeCompare(u2));
const filteredModels = useMemo(
() =>
[...userModels.entries()]
.filter(([username]) =>
username.toLowerCase().includes(searchQuery.toLowerCase())
)
.sort(([u1], [u2]) => u1.localeCompare(u2)),
[searchQuery, userModels]
);

// Disable animations automatically if there are too many displays for
// performance reasons. Unfortunately we can't seem to change the layoutId
Expand Down

0 comments on commit 2c8d6e9

Please sign in to comment.