Skip to content

Commit d51ab05

Browse files
committed
fix: typings definition
1 parent 81e9b7f commit d51ab05

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/index.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const isValidRenderProp = (prop: ReactNode | ChildrenFn<any>): boolean =>
2727

2828
export declare type RPC<RP, P = {}> = React.SFC<
2929
P & {
30-
children: ChildrenFn<RP>
30+
children?: ChildrenFn<RP>
3131
render?: ChildrenFn<RP>
3232
}
3333
>
@@ -43,7 +43,7 @@ export declare type MapperValue<RP, P> =
4343
| ReactElement<any>
4444
| MapperComponent<RP, P>
4545

46-
export declare type Mapper<RP, P> = Record<keyof RP, MapperValue<RP, P>>
46+
export declare type Mapper<RP, P> = Record<string, MapperValue<RP, P>>
4747

4848
export declare type MapProps<RP> = (props: any) => RP
4949

@@ -58,11 +58,13 @@ export function adopt<RP = any, P = any>(
5858
}
5959

6060
const mapperKeys = keys(mapper)
61-
const Children: any = ({ children, ...rest }: any) =>
62-
isFn(children) && children(rest)
61+
const Children: any = ({ render, children, ...rest }: any) =>
62+
render && isFn(render)
63+
? render(rest)
64+
: children && isFn(children) && children(rest)
6365

6466
const reducer = (Component: RPC<RP>, key: string, idx: number): RPC<RP> => ({
65-
render,
67+
render: pRender,
6668
children,
6769
...rest
6870
}) => (
@@ -71,6 +73,7 @@ export function adopt<RP = any, P = any>(
7173
const element = prop(key, mapper)
7274
const propsWithoutRest = omit<RP>(keys(rest), props)
7375
const isLast = idx === mapperKeys.length - 1
76+
const render = pRender && isFn(pRender) ? pRender : children
7477

7578
const renderFn: ChildrenFn<RP> = cProps => {
7679
const renderProps = assign({}, propsWithoutRest, {
@@ -82,11 +85,7 @@ export function adopt<RP = any, P = any>(
8285
? mapProps(renderProps)
8386
: renderProps
8487

85-
return render && isFn(render)
86-
? render(propsToPass)
87-
: isFn(children)
88-
? children(propsToPass)
89-
: null
88+
return render && isFn(render) ? render(propsToPass) : null
9089
}
9190

9291
return isFn(element)
@@ -104,7 +103,8 @@ export function adopt<RP = any, P = any>(
104103

105104
export type AdoptProps<RP, P> = P & {
106105
mapper: Mapper<RP, P>
107-
children: ChildrenFn<RP>
106+
children?: ChildrenFn<RP>
107+
render?: ChildrenFn<RP>
108108
mapProps?: MapProps<RP>
109109
}
110110

0 commit comments

Comments
 (0)