recompose: Fix fromRenderProps() with statefull render prop component

This commit is contained in:
Mathieu Masy
2018-12-12 14:25:26 -05:00
parent 1e6a34cc82
commit 07c69445a0
2 changed files with 20 additions and 8 deletions
+3 -3
View File
@@ -273,10 +273,10 @@ declare module 'recompose' {
// fromRenderProps: https://github.com/acdlite/recompose/blob/master/docs/API.md#fromrenderprops
export function fromRenderProps<TInner, TOutter, TRenderProps = {}>(
RenderPropsComponent: StatelessComponent<any>,
propsMapper: (props: TRenderProps) => Partial<TInner>,
RenderPropsComponent: Component<any>,
propsMapper: (props: TRenderProps) => TInner,
renderPropName?: string
): ComponentEnhancer<TInner, TOutter>;
): ComponentEnhancer<TInner & TOutter, TOutter>;
// Static property helpers: https://github.com/acdlite/recompose/blob/master/docs/API.md#static-property-helpers
+17 -5
View File
@@ -521,18 +521,30 @@ function testFromRenderProps() {
interface InnerProps {
renderValue: string;
outterValue: number;
}
interface OutterProps {
outterValue: number;
}
const RenderPropComponent: React.StatelessComponent<{
render: (renderProps: RenderProps) => React.ReactElement<any>;
}> = ({ render }) => render({ value: 'test' });
interface ComponentProps {
renderValue: string;
outterValue: number;
}
const component: React.StatelessComponent<InnerProps> = ({ renderValue }) => <div>{renderValue}</div>;
interface RenderComponentProps {
render: (renderProps: RenderProps) => React.ReactElement<any>;
}
class RenderPropComponent extends React.Component<RenderComponentProps> {
render () {
return this.props.render({ value: 'test' });
}
}
const component: React.StatelessComponent<ComponentProps> = ({ outterValue, renderValue }) => (
<div>{outterValue}{renderValue}</div>
);
const Enhanced = fromRenderProps<InnerProps, OutterProps, RenderProps>(
RenderPropComponent,