Created
June 5, 2017 13:25
-
-
Save BaconSoap/498b72414978206d92a3bb5d3dc006f9 to your computer and use it in GitHub Desktop.
A TypeScript connected 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
import * as React from 'react'; | |
import { connect } from 'react-redux'; | |
import { IAppState } from '../IAppState'; | |
import { doThing } from './reducer' | |
let mapDispatchToProps = { | |
doThing | |
}; | |
interface IExampleComponentProps { | |
exampleIdFromState: string; | |
} | |
export interface IExampleComponentOwnProps { | |
exampleId: string; | |
} | |
type allExampleComponentProps = IExampleComponentProps & IExampleComponentOwnProps & typeof mapDispatchToProps; | |
class ExampleComponent extends React.Component<allExampleComponentProps, undefined> { | |
public render() { | |
return (<p>Hi</p>); | |
} | |
} | |
const mapStateToProps = (state: IAppState, ownProps: IExampleComponentOwnProps): IExampleComponentProps => { | |
return { | |
exampleIdFromState: state.exampleIdFromState | |
}; | |
}; | |
export default connect(mapStateToProps, mapDispatchToProps)(ExampleComponent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment