Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/utils/buildContext/buildContext.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Interface

```ts
function buildContext(
function buildContext<ContextValuesType extends object>(
contextName: string,
defaultContextValues: ContextValuesType
): [
Expand Down Expand Up @@ -54,7 +54,7 @@ function buildContext(
```tsx
const [Provider, useContext] = buildContext<{ title: string }>(
'TestContext',
null
{ title: "" },
);

function Inner() {
Expand Down
8 changes: 5 additions & 3 deletions src/utils/buildContext/buildContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function buildContext<ContextValuesType extends object>(
contextName: string,
defaultContextValues?: ContextValuesType
) {
const Context = createContext<ContextValuesType | undefined>(defaultContextValues ?? undefined);
const Context = createContext<ContextValuesType | null>(defaultContextValues ?? null);

function Provider({ children, ...contextValues }: ProviderProps<ContextValuesType>) {
const value = useMemo(
Expand All @@ -45,14 +45,16 @@ export function buildContext<ContextValuesType extends object>(
return <Context.Provider value={value}>{children}</Context.Provider>;
}

Object.assign(Provider, { displayName: `${contextName}Provider` });

function useInnerContext() {
const context = useContext(Context);

if (context != null) {
if (context !== null) {
return context;
}

if (defaultContextValues != null) {
if (defaultContextValues !== undefined) {
return defaultContextValues;
}

Expand Down
4 changes: 2 additions & 2 deletions src/utils/buildContext/ko/buildContext.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## 인터페이스

```ts
function buildContext(
function buildContext<ContextValuesType extends object>(
contextName: string,
defaultContextValues: ContextValuesType
): [
Expand Down Expand Up @@ -54,7 +54,7 @@ function buildContext(
```tsx
const [Provider, useContext] = buildContext<{ title: string }>(
'TestContext',
null
{ title: "" },
);

function Inner() {
Expand Down
Loading