Skip to content

Commit

Permalink
refactor: chipContainer 의 useState 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
ienrum authored and HoberMin committed Jun 21, 2024
1 parent 3df1968 commit e08e1e3
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions src/app/_components/ChipContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { useState } from 'react';

import Link from 'next/link';

import Chip from '@/src/app/_components/Chip';
Expand All @@ -24,33 +22,27 @@ interface ChipContainerProps {
}

const ChipContainer = ({ currentChannel = 'all' }: ChipContainerProps) => {
const [currentPath, setCurrentPath] = useState(currentChannel);

const handleChipClick = (path: ChannelType) => () => {
setCurrentPath(path);
};

return (
<ul className='flex flex-nowrap gap-2 px-4 py-2'>
{channelData.map(({ name, path }, index) => {
const variant = path === currentPath ? 'selected' : 'default';

return (
<li key={`${index}-${name}`}>
<Link
href={{
pathname: '/',
query: path === 'all' ? {} : { channel: path },
}}
>
<Chip variant={variant} onClick={handleChipClick(path)}>
{name}
</Chip>
</Link>
</li>
);
})}
</ul>
<div className='bg-dark-accent2 sticky top-0 overflow-x-auto'>
<ul className='flex flex-nowrap gap-2 px-4 py-2'>
{channelData.map(({ name, path }, index) => {
const variant = path === currentChannel ? 'selected' : 'default';

return (
<li key={`${index}-${name}`}>
<Link
href={{
pathname: '/',
query: path === 'all' ? {} : { channel: path },
}}
>
<Chip variant={variant}>{name}</Chip>
</Link>
</li>
);
})}
</ul>
</div>
);
};

Expand Down

0 comments on commit e08e1e3

Please sign in to comment.