Skip to content

Commit b8a367c

Browse files
committed
Fix infinte render
1 parent dbd86f9 commit b8a367c

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/components/resources/CodingWithAgents.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react';
1+
import { useEffect, useMemo, useState } from 'react';
22
import codingResources from '../../data/resources/coding-with-agents.json';
33
import {
44
listSeries,
@@ -42,8 +42,12 @@ const CodingWithAgents = () => {
4242
const [selectedEpisode, setSelectedEpisode] = useState<number | null>(null);
4343
const [error, setError] = useState<string | null>(null);
4444

45-
const sortedResources = [...codingResources].sort(
46-
(a, b) => new Date(b.date).getTime() - new Date(a.date).getTime(),
45+
const sortedResources = useMemo(
46+
() =>
47+
[...codingResources].sort(
48+
(a, b) => new Date(b.date).getTime() - new Date(a.date).getTime(),
49+
),
50+
[],
4751
);
4852

4953
const getLinkText = (type: string) => {

0 commit comments

Comments
 (0)