Last active
January 31, 2018 11:46
-
-
Save junibrosas/b88992313c2b3632f648896ec4843453 to your computer and use it in GitHub Desktop.
Typescript React snippet for Visual Studio Code
This file contains 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
{ | |
"RI":{ | |
"prefix":"ri", | |
"body":["import * as React from 'react';",""], | |
"description":"import * as React from 'react';" | |
}, | |
"RC": { | |
"prefix": "rc", | |
"body": ["export interface I${Component}State { }", | |
"export interface I${Component}Props { }", | |
"", | |
"export class ${Component} extends React.Component<I${Component}Props, I${Component}State>", | |
"{", | |
"\trender()", | |
"\t{", | |
"\t\treturn <div>", | |
"\t\t\tHello", | |
"\t\t</div>", | |
"\t}", | |
"}" | |
], | |
"description": "React component (state, props, component)." | |
}, | |
"RCS": { | |
"prefix": "rcs", | |
"body": ["export interface I${Component}Props { }", | |
"", | |
"export class ${Component} extends React.Component<I${Component}Props, any>", | |
"{", | |
"\trender()", | |
"\t{", | |
"\t\treturn <div>", | |
"\t\t\tHello", | |
"\t\t</div>", | |
"\t}", | |
"}" | |
], | |
"description": "React component stateless (props, component)." | |
}, | |
"RCF":{ | |
"prefix":"rcf", | |
"body":["export interface I${Component}Props { }", | |
"", | |
"export const ${Component} = (props:I${Component}Props): JSX.Element =>", | |
"{", | |
"\treturn <div>", | |
"\t\tHello", | |
"\t</div>", | |
"}" | |
], | |
"description":"React component functional (props, function)." | |
}, | |
"RCC": { | |
"prefix": "rcc", | |
"body": ["import * as React from 'react';", | |
"", | |
"export interface I${Component}ContainerState { }", | |
"export interface I${Component}ContainerProps { }", | |
"", | |
"export class ${Component}Container extends React.Component<I${Component}ContainerProps, I${Component}ContainerState>", | |
"{", | |
"\trender()", | |
"\t{", | |
"\t\treturn <div>", | |
"\t\t\tHello", | |
"\t\t</div>", | |
"\t}", | |
"}" | |
], | |
"description": "React component container (state, props, container)." | |
}, | |
"RT":{ | |
"description":"Component and Redux container template.", | |
"prefix":"rt", | |
"body":["import * as React from 'react';", | |
"import { connect } from 'react-redux';", | |
"import { IKrelosesState } from '../../../../main/state';", | |
"", | |
"const component = (props: IProps): JSX.Element =>", | |
"{", | |
"\treturn <div>", | |
"\t\tHello World.", | |
"\t</div>", | |
"}", | |
"", | |
"/**", | |
"* Props.", | |
"*/", | |
"", | |
"interface IDataProps", | |
"{", | |
"", | |
"}", | |
"interface IDispatchProps", | |
"{", | |
"", | |
"}", | |
"interface IProps extends IDataProps, IDispatchProps { }", | |
"", | |
"/**", | |
"* Container.", | |
"*/", | |
"", | |
"var stateToProps = (state: IKrelosesState): IDataProps =>", | |
"{", | |
"\treturn {", | |
"", | |
"\t}", | |
"}", | |
"", | |
"var dispatchToProps = (dispatch: (action: any) => void): IDispatchProps => ", | |
"{", | |
"\treturn {", | |
"", | |
"\t}", | |
"}", | |
"", | |
"var container = connect(stateToProps, dispatchToProps)(component);", | |
"", | |
"/**", | |
"* Exports.", | |
"*/", | |
"", | |
"export { container as ${Component}Container };"] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment