Skip to content

Commit

Permalink
Remove unnecessary useCallback calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ex_suzhonghui committed Mar 6, 2024
1 parent bf4c98a commit a1db1a0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
15 changes: 6 additions & 9 deletions src/app/(defi)/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
import dynamic from 'next/dynamic';
import { useState, startTransition, Suspense, useCallback } from 'react';
import { useState, startTransition, Suspense } from 'react';
import { useSearchParams, useRouter, usePathname } from 'next/navigation';
import { motion, AnimatePresence } from 'framer-motion';

Expand Down Expand Up @@ -36,14 +36,11 @@ const DefiTabs = () => {

const value = searchParams.get('type') || defaultValue;

const handleClick = useCallback(
(key: (typeof menuItems)[number]['key']) => {
startTransition(() => {
router.push(`${pathname}?type=${key}`);
});
},
[router, pathname]
);
const handleClick = (key: (typeof menuItems)[number]['key']) => {
startTransition(() => {
router.push(`${pathname}?type=${key}`);
});
};

return (
<Tabs defaultValue={defaultValue} className="w-full" value={value}>
Expand Down
13 changes: 5 additions & 8 deletions src/components/amount-input-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ const AmountInputForm = forwardRef<Form, AmountInputFormProps>(
return true;
}, [watchedAmount, etherBalance, setError, clearErrors]);

const handleFormSubmit = (data: z.infer<typeof formSchema>) => {
const isValid = validateAmount();
isValid && onSubmit(data);
};

useEffect(() => {
if (watchedAmount === '') {
onAmountChange && onAmountChange(watchedAmount);
Expand All @@ -75,14 +80,6 @@ const AmountInputForm = forwardRef<Form, AmountInputFormProps>(
}
}, [watchedAmount, validateAmount, onAmountChange]);

const handleFormSubmit = useCallback(
(data: z.infer<typeof formSchema>) => {
const isValid = validateAmount();
isValid && onSubmit(data);
},
[validateAmount, onSubmit]
);

useImperativeHandle(ref, () => form, [form]);

return (
Expand Down
6 changes: 3 additions & 3 deletions src/components/connect-button/account.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import { useCallback, useRef } from 'react';
import { useRef } from 'react';
import Jazzicon, { jsNumberForAddress } from 'react-jazzicon';
import { useCopyToClipboard } from 'react-use';
import { toast } from 'sonner';
Expand All @@ -17,12 +17,12 @@ const Account = ({ address }: AccountProps) => {
const toastRef = useRef<string | number | null>(null);
const [, copyToClipboard] = useCopyToClipboard();

const handleCopy = useCallback(() => {
const handleCopy = () => {
copyToClipboard(address);
toastRef.current = toast('✅ Address successfully copied to clipboard.', {
duration: 2000
});
}, [address, copyToClipboard]);
};

return address ? (
<Button title="Click to copy the address to your clipboard" onClick={handleCopy}>
Expand Down

0 comments on commit a1db1a0

Please sign in to comment.