Last active
April 14, 2017 07:54
-
-
Save moaible/3c588eca34dd69bf8b7a451ac882ae71 to your computer and use it in GitHub Desktop.
Typed React Component
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
| /* @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