Last active
December 17, 2019 17:20
-
-
Save marcolink/2b4425cfb835770399d47c11853a58f8 to your computer and use it in GitHub Desktop.
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
import * as React from "react"; | |
function useRenderComponent<T>(Component: React.FC, initialProps?: T) { | |
const [props, setProps] = React.useState<T>(initialProps); | |
const updateProps = <K extends keyof T>( | |
field: K, | |
value: T[K] | |
) => | |
setProps((prevState: T) => ({ | |
...prevState, | |
[field]: value | |
})); | |
return { | |
component: <Component {...props} />, | |
updateProps | |
}; | |
}; | |
export {useRenderComponent}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment