Merge pull request #15016 from sjpurol/withHandlers-factory

recompose: withHandlers may take a factory function
This commit is contained in:
Paul van Brenk
2017-03-21 17:29:37 -07:00
committed by GitHub
2 changed files with 9 additions and 2 deletions
+3 -2
View File
@@ -1,4 +1,4 @@
// Type definitions for Recompose v0.20.3
// Type definitions for Recompose v0.22.0
// Project: https://github.com/acdlite/recompose
// Definitions by: Iskander Sierra <https://github.com/iskandersierra>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -50,8 +50,9 @@ declare module 'recompose' {
type HandleCreators<TOutter> = {
[handlerName: string]: mapper<TOutter, EventHandler>;
};
type HandleCreatorsFactory<TOutter> = (initialProps: TOutter) => HandleCreators<TOutter>;
export function withHandlers<TInner, TOutter>(
handlerCreators: HandleCreators<TOutter>
handlerCreators: HandleCreators<TOutter> | HandleCreatorsFactory<TOutter>
): ComponentEnhancer<TInner, TOutter>;
// defaultProps: https://github.com/acdlite/recompose/blob/master/docs/API.md#defaultprops
+6
View File
@@ -73,6 +73,12 @@ function testWithHandlers() {
onSubmit: (props: OutterProps) => (e: any) => {},
});
const enhanced: React.ComponentClass<OutterProps> = enhancer(innerComponent);
const enhancer2 = withHandlers((props: OutterProps) => ({
onChange: (props: OutterProps) => (e: any) => {},
onSubmit: (props: OutterProps) => (e: any) => {},
}));
const enhanced2: React.ComponentClass<OutterProps> = enhancer2(innerComponent);
}
function testDefaultProps() {