Skip to content

Commit fab2270

Browse files
committed
♻️ Refactor error handling and code readability across modules
1 parent b40786b commit fab2270

6 files changed

Lines changed: 19 additions & 20 deletions

File tree

src/base/hooks/use-is-mounted.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ export const useIsMounted = () => {
99
const [isMounted, setMounted] = useState(false);
1010

1111
useEffect(() => {
12-
setMounted(true);
12+
// 마운트 직후(다음 tick)에만 true로 바꿔서 "렌더 중 state 변경" ESLint 경고 대응
13+
const timer = setTimeout(() => {
14+
setMounted(true);
15+
}, 0);
1316

1417
return () => {
18+
clearTimeout(timer);
1519
setMounted(false);
1620
};
1721
}, []);

src/base/hooks/use-local-storage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const safeSetItem = <T>(key: string, value: T) => {
1717

1818
try {
1919
window.localStorage.setItem(key, JSON.stringify(value));
20-
} catch (error) {
20+
} catch {
2121
logError('setting', key);
2222
}
2323
};
@@ -28,7 +28,7 @@ const safeGetItem = <T>(key: string, defaultValue: T) => {
2828
try {
2929
const storedValue = window.localStorage.getItem(key);
3030
if (storedValue) return JSON.parse(storedValue) as T;
31-
} catch (error) {
31+
} catch {
3232
logError('getting', key);
3333
}
3434

src/base/utils/selection.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ interface SelectionIndicesResult {
1616
export const getSelectionIndices = (
1717
qualifiedName: string,
1818
): SelectionIndicesResult => {
19-
let begin = 0;
20-
let end = 0;
21-
2219
const sel = window.getSelection();
2320
if (!sel?.rangeCount) {
2421
return { begin: 0, end: 0, startNode: null, endNode: null };
@@ -36,8 +33,8 @@ export const getSelectionIndices = (
3633
const startIndex = startElement.getAttribute(qualifiedName);
3734
const endIndex = endElement.getAttribute(qualifiedName);
3835

39-
begin = startIndex ? Number(startIndex) : 0;
40-
end = endIndex ? Number(endIndex) + 1 : 0;
36+
const begin = startIndex ? Number(startIndex) : 0;
37+
const end = endIndex ? Number(endIndex) + 1 : 0;
4138

4239
return { begin, end, startNode: startElement, endNode: endElement };
4340
};

src/features/misc/pages/error-component.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { useRef } from 'react';
2-
31
import {
42
Button,
53
Heading,
@@ -34,12 +32,12 @@ export default function ErrorComponent({
3432
const [shouldRedirect, setShouldRedirect] = useBoolean(false);
3533

3634
const isMounted = useIsMounted();
37-
const errorMessage = useRef(error?.message ?? '문제가 발생했어요');
35+
let errorMessage = error?.message ?? '문제가 발생했어요';
3836

3937
const isRouteError = isRouteErrorResponse(routerError);
4038
if (isRouteError) {
4139
const { status, statusText } = routerError;
42-
errorMessage.current = `${status} | ${statusText}`;
40+
errorMessage = `${status} | ${statusText}`;
4341
}
4442

4543
const onActionButtonClick = isRouteError
@@ -69,10 +67,10 @@ export default function ErrorComponent({
6967
<VStack>
7068
<Text fontSize="xl" textTransform="capitalize" maxW={500}>
7169
<Highlight
72-
query={errorMessage.current.match(DIGITS_PATTERN) ?? []}
70+
query={errorMessage.match(DIGITS_PATTERN) ?? []}
7371
styles={highlightStyles}
7472
>
75-
{errorMessage.current}
73+
{errorMessage}
7674
</Highlight>
7775
</Text>
7876
<Button mt={2} w="full" maxW={232} onClick={onActionButtonClick}>

src/features/syntax-analyzer/components/analysis-form/analysis-form.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ const AnalysisFormBox = ({
8484
);
8585
};
8686

87-
const AnalysisFormSkeleton = (stackProps: StackProps) => {
88-
const ESkeleton = (props: SkeletonProps) => (
89-
<Skeleton w="full" borderRadius="md" h={10} {...props} />
90-
);
87+
const ESkeleton = (props: SkeletonProps) => (
88+
<Skeleton w="full" borderRadius="md" h={10} {...props} />
89+
);
9190

91+
const AnalysisFormSkeleton = (stackProps: StackProps) => {
9292
return (
9393
<AnalysisFormBox {...stackProps}>
9494
<Stack gap={5} mb={2}>

src/lib/axios.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Axios from 'axios';
1+
import axiosLib from 'axios';
22
import { stringify } from 'qs';
33

44
const baseURL = import.meta.env.DEV
@@ -9,4 +9,4 @@ export const paramsSerializer = <T>(params: T) => {
99
return stringify(params, { arrayFormat: 'repeat' });
1010
};
1111

12-
export const axios = Axios.create({ baseURL });
12+
export const axios = axiosLib.create({ baseURL });

0 commit comments

Comments
 (0)