Skip to content

Commit

Permalink
[FE] Feat #133: useStoreBucketInfo로 데이터 fetch 시 전역 데이터에 저장
Browse files Browse the repository at this point in the history
Change-Id: Ifb902a68f5d52039343448f34768beaf3d1dac4c
  • Loading branch information
leewooseong committed Feb 13, 2024
1 parent 402762b commit 9d02ee4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions frontend/src/hooks/useStoreBucketInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { useEffect } from 'react'
import { useBucketStore } from '../store/bucketStore'
import { IBucketInfo } from '../interfaces'

const useStoreBucketInfo = (bucketInfo: IBucketInfo | undefined) => {
const { addBucketState, resetAllState } = useBucketStore()
useEffect(() => {
resetAllState()
if (bucketInfo) {
addBucketState(bucketInfo)
}
return () => {
resetAllState()
}
}, [bucketInfo])
}

export default useStoreBucketInfo
2 changes: 2 additions & 0 deletions frontend/src/pages/Bucket/BucketDetail/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { IBucketDetailInfo, IMenu, IMenuFunc } from '../../../interfaces'
import { icons } from '../../../constants/header-icons'
import BucketMoreButton from './component/BucketMoreButton'
import { isMyUserType } from './../../../utils/typeFilter'
import useStoreBucketInfo from '../../../hooks/useStoreBucketInfo'

const BucketDetail = () => {
const [isInputShown, setIsInputShown] = useState(false)
Expand All @@ -44,6 +45,7 @@ const BucketDetail = () => {
queryKey: ['bucketInfo', bucketId],
queryFn: getBucketDetailInfo,
})
useStoreBucketInfo(bucketDetailInfo?.bucketInfo)

// :: Header
const bucketRightMenu =
Expand Down

0 comments on commit 9d02ee4

Please sign in to comment.