Skip to content

Commit 00ca5ad

Browse files
authored
Replace immer with spread syntax for state updates (#897)
1 parent 184b568 commit 00ca5ad

File tree

4 files changed

+2
-16
lines changed

4 files changed

+2
-16
lines changed

client/src/components/course-averages.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { produce } from 'immer';
21
import { ChevronDown, ChevronUp, LineChart, List } from 'lucide-react';
32
import { Fragment, useCallback, useEffect, useState } from 'react';
43
import { Link } from 'react-router-dom';
@@ -37,11 +36,7 @@ export const CourseAverages = ({ course, averages }: CourseAveragesProps) => {
3736
const [expandedState, setExpandedState] = useState(initialExpandedState());
3837

3938
const handleInstructorToggle = (term: string) => {
40-
setExpandedState(
41-
produce(expandedState, (draft) => {
42-
draft[term] = !draft[term];
43-
})
44-
);
39+
setExpandedState({ ...expandedState, [term]: !expandedState[term] });
4540
};
4641

4742
const handleGraphToggle = useCallback(

client/src/components/course-terms.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { produce } from 'immer';
21
import { ChevronDown } from 'lucide-react';
32
import { Leaf, Snowflake, Sun, X } from 'lucide-react';
43
import { useEffect, useState } from 'react';
@@ -68,11 +67,7 @@ export const CourseTerms = ({ course, variant, query }: CourseTermsProps) => {
6867
const [expandedState, setExpandedState] = useState(initialExpandedState());
6968

7069
const handleToggle = (i: number) => {
71-
setExpandedState(
72-
produce(expandedState, (draft) => {
73-
draft[i] = !draft[i];
74-
})
75-
);
70+
setExpandedState(expandedState.map((val, idx) => (idx === i ? !val : val)));
7671
};
7772

7873
useEffect(() => {

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
"flexsearch": "^0.8.212",
2929
"formik": "^2.4.9",
3030
"framer-motion": "^12.27.1",
31-
"immer": "^11.1.3",
3231
"lucide-react": "^0.562.0",
3332
"react": "^18.3.1",
3433
"react-dom": "^18.3.1",

pnpm-lock.yaml

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)