Skip to content

Instantly share code, notes, and snippets.

@limscoder
Created October 14, 2016 20:43
Show Gist options
  • Save limscoder/a45eca06f3c6c77fbfc1c614830b223d to your computer and use it in GitHub Desktop.
Save limscoder/a45eca06f3c6c77fbfc1c614830b223d to your computer and use it in GitHub Desktop.
Playing with ways to express immutable react elements with flowtype
type FunctionComponent<P, S> = (props: P, context: S) => ?React$Element<any>;
type ClassComponent<D, P, S> = Class<React$Component<D, P, S>>;
type ReactComponent<D, P, S> = FunctionComponent<P, S> | ClassComponent<D, P, S>;
function ImmutableComponent<D, P, S, T: ReactComponent<D, P, S>>({ component: Component, componentProps }: {
component: T,
componentProps: P
}) {
return <Component { ...componentProps }/>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment