mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 08:41:37 +00:00
Add useCallback
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import { useRouter } from 'next/router';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
|
||||
/**
|
||||
* Loading state when router changed.
|
||||
@ -9,12 +9,15 @@ const useRouterLoading = () => {
|
||||
const router = useRouter();
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const handleStart = (url: string) => {
|
||||
const handleStart = useCallback(
|
||||
(url: string) => {
|
||||
url !== router.pathname ? setLoading(true) : setLoading(false);
|
||||
};
|
||||
const handleComplete = () => {
|
||||
},
|
||||
[router.pathname]
|
||||
);
|
||||
const handleComplete = useCallback(() => {
|
||||
setLoading(false);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
router.events.on('routeChangeStart', handleStart);
|
||||
|
Reference in New Issue
Block a user