From a152a7e0e321795eb7c99f356a2cd0dc2358a9eb Mon Sep 17 00:00:00 2001 From: brgndy Date: Sat, 12 Oct 2024 12:47:22 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=BB=A8=ED=85=8D=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=ED=83=80=EC=9E=85=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/react/react/package.json | 2 +- packages/react/react/src/utils/buildContext.tsx | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/react/react/package.json b/packages/react/react/package.json index 2918a2e..56727be 100644 --- a/packages/react/react/package.json +++ b/packages/react/react/package.json @@ -1,6 +1,6 @@ { "name": "@brgndy/react", - "version": "1.0.3", + "version": "1.0.4", "sideEffects": false, "main": "dist/index.js", "module": "dist/index.esm.js", diff --git a/packages/react/react/src/utils/buildContext.tsx b/packages/react/react/src/utils/buildContext.tsx index aec213b..a686420 100644 --- a/packages/react/react/src/utils/buildContext.tsx +++ b/packages/react/react/src/utils/buildContext.tsx @@ -1,4 +1,4 @@ -import React, { createContext, useContext, useState, useMemo, ReactNode } from 'react'; +import { createContext, useContext, useState, useMemo, ReactNode } from 'react'; type ProviderProps = { children: ReactNode; @@ -6,7 +6,9 @@ type ProviderProps = { }; export function buildContext(contextName: string, defaultContext: T) { - const Context = createContext(null); + type ContextWithUpdate = T & { updateContext: (updates: Partial) => void }; + + const Context = createContext(null); function Provider({ children, value }: ProviderProps) { const [state, setState] = useState(() => ({ @@ -28,10 +30,10 @@ export function buildContext(contextName: string, defaultConte return {children}; } - function useContextHook(): T { + function useContextHook(): ContextWithUpdate { const context = useContext(Context); - if (context === null || undefined) { + if (context === null || context === undefined) { throw new Error(`use${contextName} must be used within a ${contextName}Provider`); }