Skip to content

Commit f20a969

Browse files
feat: debounce로 검색 API 최적화
1 parent e4520af commit f20a969

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Diff for: app/posts/page.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react';
44
import { Post } from '@/app/types/Post';
55
import PostList from '@/app/entities/post/list/PostList';
66
import SearchSection from '@/app/entities/post/list/SearchSection';
7+
import { debounce } from 'lodash';
78

89
const BlogList = () => {
910
const [posts, setPosts] = useState<Post[]>();
@@ -20,8 +21,10 @@ const BlogList = () => {
2021
setLoading(false);
2122
};
2223

24+
const debouncedGetPosts = debounce(getPosts, 500);
25+
2326
useEffect(() => {
24-
getPosts(query);
27+
debouncedGetPosts(query);
2528
}, [query]);
2629

2730
return (

Diff for: package.json

+2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212
},
1313
"dependencies": {
1414
"@next/third-parties": "^15.1.2",
15+
"@types/lodash": "^4.17.13",
1516
"@uiw/react-md-editor": "^4.0.4",
1617
"@vercel/blob": "^0.27.0",
1718
"axios": "^1.7.9",
19+
"lodash": "^4.17.21",
1820
"mongoose": "^8.9.0",
1921
"next": "14.2.13",
2022
"next-auth": "^4.24.11",

0 commit comments

Comments
 (0)