Skip to content

Instantly share code, notes, and snippets.

@rcarton
Last active September 26, 2024 00:51
Show Gist options
  • Save rcarton/7be0106e85627bdc540c1ffed2d446f1 to your computer and use it in GitHub Desktop.
Save rcarton/7be0106e85627bdc540c1ffed2d446f1 to your computer and use it in GitHub Desktop.
Put this in React typescript snippets
"React Connected Component": {
"prefix": "cc",
"body": [
"import * as React from 'react'",
"import { connect } from 'react-redux'",
"",
"export interface OwnProps {}",
"interface StateProps {}",
"interface DispatchProps {}",
"",
"export type Props = OwnProps & StateProps & DispatchProps",
"",
"export class ${1:ComponentName} extends React.Component<Props, {}> {",
"\trender(): JSX.Element {",
"\t\treturn (",
"\t\t\t<div>",
"\t\t\t\t${1:ComponentName}",
"\t\t\t</div>",
"\t\t)",
"\t}",
"}",
"",
"export function mapStateToProps(state, ownProps: OwnProps): StateProps {",
"\treturn {}",
"}",
"",
"export function mapDispatchToProps(dispatch): DispatchProps { ",
"\treturn {}",
"}",
"",
"export default connect<StateProps, DispatchProps, OwnProps>(",
"\tmapStateToProps,",
"\tmapDispatchToProps",
")(${1:ComponentName})"
],
"description": "Connected React Component"
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment