Remove redundant useCallbacks

This commit is contained in:
Justin Spahr-Summers
2024-11-08 12:00:46 +00:00
parent 5337baa116
commit 57f0c49154

View File

@@ -4,7 +4,6 @@ import { Input } from "@/components/ui/input";
import { TabsContent } from "@/components/ui/tabs"; import { TabsContent } from "@/components/ui/tabs";
import { Root } from "@modelcontextprotocol/sdk/types.js"; import { Root } from "@modelcontextprotocol/sdk/types.js";
import { Plus, Minus, Save } from "lucide-react"; import { Plus, Minus, Save } from "lucide-react";
import { useCallback } from "react";
const RootsTab = ({ const RootsTab = ({
roots, roots,
@@ -15,31 +14,25 @@ const RootsTab = ({
setRoots: React.Dispatch<React.SetStateAction<Root[]>>; setRoots: React.Dispatch<React.SetStateAction<Root[]>>;
onRootsChange: () => void; onRootsChange: () => void;
}) => { }) => {
const addRoot = useCallback(() => { const addRoot = () => {
setRoots((currentRoots) => [...currentRoots, { uri: "file://", name: "" }]); setRoots((currentRoots) => [...currentRoots, { uri: "file://", name: "" }]);
}, [setRoots]); };
const removeRoot = useCallback( const removeRoot = (index: number) => {
(index: number) => { setRoots((currentRoots) => currentRoots.filter((_, i) => i !== index));
setRoots((currentRoots) => currentRoots.filter((_, i) => i !== index)); };
},
[setRoots],
);
const updateRoot = useCallback( const updateRoot = (index: number, field: keyof Root, value: string) => {
(index: number, field: keyof Root, value: string) => { setRoots((currentRoots) =>
setRoots((currentRoots) => currentRoots.map((root, i) =>
currentRoots.map((root, i) => i === index ? { ...root, [field]: value } : root,
i === index ? { ...root, [field]: value } : root, ),
), );
); };
},
[setRoots],
);
const handleSave = useCallback(() => { const handleSave = () => {
onRootsChange(); onRootsChange();
}, [onRootsChange]); };
return ( return (
<TabsContent value="roots" className="space-y-4"> <TabsContent value="roots" className="space-y-4">