Skip to content

Instantly share code, notes, and snippets.

@BaconSoap
Created June 5, 2017 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BaconSoap/498b72414978206d92a3bb5d3dc006f9 to your computer and use it in GitHub Desktop.
Save BaconSoap/498b72414978206d92a3bb5d3dc006f9 to your computer and use it in GitHub Desktop.
A TypeScript connected component
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