-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
게시글 옵션을 ContextApi를 이용해 전역으로 관리 (#288)
* feat: (#282) 게시글 옵션을 ContextApi를 이용해 전역으로 관리 상세 게시글을 보다가 뒤로가기를 하여도 원래 보던 옵션 게시글 목록이 나오도록 하기 위해서 * refactor: (#282) Provider를 RouterProvider만 감싸도록 수정 contextApi를 사용하며 setPostOption의 타입을 선언하는 곳에서 Dispatch, SetStateAction를 사용하도록 수정
- Loading branch information
1 parent
4c480f8
commit e6fd855
Showing
4 changed files
with
63 additions
and
14 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Dispatch, PropsWithChildren, SetStateAction, createContext, useState } from 'react'; | ||
|
||
import type { PostSorting, PostStatus } from '@components/post/PostListPage/types'; | ||
|
||
import { SORTING, STATUS } from '@constants/post'; | ||
|
||
export const PostOptionContext = createContext<PostOptionContextProps>({ | ||
postOption: { sorting: SORTING.LATEST, status: STATUS.PROGRESS }, | ||
setPostOption: () => {}, | ||
}); | ||
|
||
interface PostOption { | ||
status: PostStatus; | ||
sorting: PostSorting; | ||
} | ||
interface PostOptionContextProps { | ||
postOption: PostOption; | ||
setPostOption: Dispatch<SetStateAction<PostOption>>; | ||
} | ||
|
||
export default function PostOptionProvider({ children }: PropsWithChildren) { | ||
const [postOption, setPostOption] = useState<PostOption>({ | ||
sorting: SORTING.LATEST, | ||
status: STATUS.PROGRESS, | ||
}); | ||
|
||
return ( | ||
<PostOptionContext.Provider value={{ postOption, setPostOption }}> | ||
{children} | ||
</PostOptionContext.Provider> | ||
); | ||
} |