Skip to content

Instantly share code, notes, and snippets.

@moaible
Last active April 14, 2017 07:54
Show Gist options
  • Select an option

  • Save moaible/3c588eca34dd69bf8b7a451ac882ae71 to your computer and use it in GitHub Desktop.

Select an option

Save moaible/3c588eca34dd69bf8b7a451ac882ae71 to your computer and use it in GitHub Desktop.
Typed React Component
/* @flow */
import React from 'react'
export interface ReactComponentable<T, U> {
props: T;
state: U;
configureStateFor(props: T): ?U;
}
export class TypedReactComponent<T, U> extends React.Component<*, *, *> implements ReactComponentable<T, U> {
static defaultProps: T;
props: T;
state: U;
constructor(props: T) {
super(props)
let state = this.configureStateFor(props)
if (state) {
this.state = state
}
}
configureStateFor(props: T): ?U {
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment