Skip to content

Instantly share code, notes, and snippets.

@marcolink
Last active December 17, 2019 17:20
Show Gist options
  • Save marcolink/2b4425cfb835770399d47c11853a58f8 to your computer and use it in GitHub Desktop.
Save marcolink/2b4425cfb835770399d47c11853a58f8 to your computer and use it in GitHub Desktop.
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