Skip to content

Commit

Permalink
feat : DropDownOption 에 use client 추가, useSafeContext 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
SeieunYoo committed Jul 21, 2024
1 parent dc8c589 commit 6b3db85
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions apps/wow-docs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const Home = () => {
<RadioButton label="2학년" value="2학년" />
</RadioGroup>
<DropDown placeholder="목록을 입력하세요">
<DropDownOption text="option 1" value="option 1" />
<DropDownOption text="option 1" value="option 2" />
<DropDownOption text=" 1" value="option 1" />
<DropDownOption text="옵 2" value="option 2" />
</DropDown>
<MultiGroup variant="checkbox">
<Checkbox label="checkbox1" value="checkbox1" />
Expand Down
2 changes: 2 additions & 0 deletions packages/wow-ui/src/components/DropDown/DropDownOption.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use client";

import { cva } from "@styled-system/css";
import { styled } from "@styled-system/jsx";
import type { ReactNode } from "react";
Expand Down
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;
};
12 changes: 12 additions & 0 deletions packages/wow-ui/src/hooks/useSafeContext.ts
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;

0 comments on commit 6b3db85

Please sign in to comment.