Last active
August 29, 2017 06:20
-
-
Save benmvp/69799153880d42d2ef2bb9f1ff9012b8 to your computer and use it in GitHub Desktop.
Need Dynamic HOC Flow help
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const myHOC = <Props: {}>( | |
Component: React.ComponentType<{}> | |
): React.ComponentType<Props> ( | |
(props: Props) = { | |
let handlers = genDynamicAdditionalProps(props.eventName) | |
// The keys in `additionalProps` are dependent upon `props.eventName` value | |
// The values in `additionalProps` are all functions | |
let propsToPassThru = {...props} | |
delete propsToPassThru[props.eventName] | |
// Also removing `props.eventName` from `props`! | |
return ( | |
<Component | |
{...propsToPassThru} | |
{...handlers} | |
/> | |
) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sorry, I missed your post! I would love to figure out a way to make it work if you're up for it. It'll certainly help me learn more Flow along the way.
So what I put in the gist is stripped down version of the full code, which is part of benmvp/react-composite-events#9. Essentially there's a function that takes a configuration of options that ends up returning the HOC above. So
props.eventName
in the example above ends up beingprops[eventPropName]
, making it even more dynamic.In case you're curious what this is all about, here are the docs for the utility function: https://github.com/benmvp/react-composite-events/blob/master/src/compose.md
Thanks for the help!