Created
July 4, 2019 19:00
-
-
Save icarus-sullivan/719b797fe1102f221f295e13c3f79125 to your computer and use it in GitHub Desktop.
HOC for useAsync
This file contains hidden or 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
// ... useAysnc code above | |
export const withAsync = (fn, ...vargs]) => (Component) => ({ args, ...props }) => { | |
// If users override args in props, use those instead of vargs | |
const conditionalArgs = args || vargs; | |
// merge useAsync props with given props | |
const mergeProps = { | |
...props, | |
...useAsync(fn, ...conditionalArgs), | |
}; | |
// inject all mergeProps | |
return ( | |
<Component {...mergeProps} /> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment