Skip to content

Commit 610974a

Browse files
committed
Add type arguments
1 parent 77df96e commit 610974a

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/components/DefaultComponents.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ const Overlay: React.FC = () => {
3030
return <div style={overlayStyle} />;
3131
};
3232

33-
const Modal: React.FC<ModalProps<{}>> = ({ children }) => {
33+
const Modal = <T extends Record<string, unknown>>({
34+
children,
35+
}: ModalProps<T>): React.ReactElement | null => {
3436
return <Fragment>{children}</Fragment>;
3537
};
3638

src/components/ModalProvider.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ import React from 'react';
22
import { UseModalOptions } from '..';
33
import { ModalConfigContext } from '../hooks/useModalConfig';
44

5-
interface ModalProviderProps<T extends Record<string, unknown>>
6-
extends UseModalOptions<T> {
5+
interface ModalProviderProps extends UseModalOptions<{}> {
76
children?: React.ReactNode;
87
}
98

10-
export const ModalProvider = <T extends Record<string, unknown>>({
9+
export const ModalProvider: React.FC<ModalProviderProps> = ({
1110
children,
1211
...props
13-
}: ModalProviderProps<T>): React.ReactElement | null => {
12+
}) => {
1413
return (
1514
<ModalConfigContext.Provider value={props}>
1615
{children}

src/hooks/useModalConfig.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { createContext, useContext } from 'react';
1+
import React, { createContext, useContext } from 'react';
22
import { UseModalOptions } from '..';
33

4-
export const ModalConfigContext = createContext<UseModalOptions>({});
4+
export const ModalConfigContext = createContext<UseModalOptions<{}>>({});
55

6-
export const useModalConfig = () => {
7-
return useContext(ModalConfigContext);
6+
export const useModalConfig = <T extends Record<string, unknown>>() => {
7+
return useContext(ModalConfigContext) as React.Context<UseModalOptions<T>>;
88
};

src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export const useModal = <T extends Record<string, unknown>>(
6464
elementId = 'root',
6565
options?: UseModalOptions<T>
6666
): UseModalResult<T> => {
67-
const modalConfig = useModalConfig();
67+
const modalConfig = useModalConfig<T>();
6868
const { initialValue, preventScroll, focusTrapOptions, components } = useMemo(
6969
() => Object.assign({}, defaultOptions, modalConfig, options),
7070
[modalConfig, options]

0 commit comments

Comments
 (0)