-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ refactor ] seperate filter tag value with custom hook
- Loading branch information
1 parent
756d3d5
commit cfed6dc
Showing
3 changed files
with
41 additions
and
31 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/@components/CardCollectionPage/FilterModal/@hooks/useFilterTags.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useEffect } from "react"; | ||
import { useRecoilState } from "recoil"; | ||
|
||
import { filterTagsState } from "../../../../core/atom/slider"; | ||
|
||
export default function useFilterTags() { | ||
const [filterTags, setFilterTags] = useRecoilState(filterTagsState); | ||
|
||
useEffect(() => { | ||
if (!filterTags.isActive) setFilterTags({ tags: new Set(), intimacy: [0], isActive: false }); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [filterTags.isActive]); | ||
|
||
// 태그를 눌렀을 때 함수 | ||
const toggleTag = (_tag: string) => { | ||
if (_tag === "19금") return; | ||
|
||
setFilterTags((prevFilterTags) => { | ||
const tempCheckedTags = new Set(filterTags.tags); | ||
tempCheckedTags.has(_tag) ? tempCheckedTags.delete(_tag) : tempCheckedTags.add(_tag); | ||
return { ...prevFilterTags, tags: tempCheckedTags }; | ||
}); | ||
}; | ||
|
||
const handleChangeIntimacyValue = (values: number[]) => { | ||
setFilterTags((prevFilterTags) => { | ||
return { ...prevFilterTags, intimacy: values }; | ||
}); | ||
}; | ||
|
||
return { filterTags, toggleTag, handleChangeIntimacyValue }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters