-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat : DropDownOption 에 use client 추가, useSafeContext 추가
- Loading branch information
Showing
4 changed files
with
18 additions
and
10 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
10 changes: 2 additions & 8 deletions
10
packages/wow-ui/src/components/DropDown/context/DropDownContext.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 |
---|---|---|
@@ -1,19 +1,13 @@ | ||
"use client"; | ||
|
||
import { createContext, useContext } from "react"; | ||
|
||
import type useDropDownState from "@/hooks/useDropDownState"; | ||
import useSafeContext from "@/hooks/useSafeContext"; | ||
|
||
export const DropDownContext = createContext< | ||
ReturnType<typeof useDropDownState> | undefined | ||
>(undefined); | ||
|
||
export const useDropDownContext = () => { | ||
const context = useContext(DropDownContext); | ||
if (!context) { | ||
throw new Error( | ||
"useDropDownContext must be used within a DropDownProvider" | ||
); | ||
} | ||
const context = useSafeContext(DropDownContext); | ||
return context; | ||
}; |
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,12 @@ | ||
import type { Context } from "react"; | ||
import { useContext } from "react"; | ||
|
||
const useSafeContext = <T>(context: Context<T | undefined>): T => { | ||
const contextValue = useContext(context); | ||
if (contextValue === undefined) { | ||
throw new Error(`useSafeContext must be used within a context provider`); | ||
} | ||
return contextValue; | ||
}; | ||
|
||
export default useSafeContext; |