Skip to content

Commit

Permalink
refactor: 불필요한 리렌더링 개선(#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbgksqkr committed Jun 18, 2024
1 parent 5d2fe97 commit 881e47c
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/components/search/searchBodySection/SearchBodySection.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { useRouter, useSearchParams } from 'next/navigation';
import React, { useEffect, useState } from 'react';
import React, { Suspense, useEffect, useState } from 'react';
import SearchForm from '../SearchForm';
import * as S from './SearchBodySection.styled';
import { useSearchQuery } from '@/hooks/useSearchQuery';
Expand All @@ -10,13 +10,9 @@ import SearchResultContainer from '../SearchResult';
const SearchBodySection = () => {
const router = useRouter();
const params = useSearchParams();
const [searchKeyword, setSearchKeyword] = useState('');
const { data: searchResult, isPending } = useSearchQuery(searchKeyword);

useEffect(() => {
const searchParams = params.get('search')!;
setSearchKeyword(searchParams);
}, [params]);
const searchKeyword = params.get('search') || '멋쟁이사자처럼';
const { data: searchResult } = useSearchQuery(searchKeyword);

useEffect(() => {
if (searchResult && searchResult.kind === 'searchResult') {
Expand All @@ -39,7 +35,7 @@ const SearchBodySection = () => {
</S.TextImageWrapper>
<SearchForm searchKeyword={searchKeyword} type="search" />
</S.SearchBarWrapper>
<SearchResultContainer searchResult={searchResult} searchKeyword={searchKeyword} isPending={isPending} />
<SearchResultContainer searchResult={searchResult} searchKeyword={searchKeyword} />
</>
);
};
Expand Down

0 comments on commit 881e47c

Please sign in to comment.