Skip to content

Instantly share code, notes, and snippets.

@algera
Last active September 11, 2020 05:49
Show Gist options
  • Save algera/7e131cfead1fbc1dfe10a9f129554cb6 to your computer and use it in GitHub Desktop.
Save algera/7e131cfead1fbc1dfe10a9f129554cb6 to your computer and use it in GitHub Desktop.
React / Redux Code Snippets for Visual Studio Code
{
"Jeff's Component": {
"scope": "javascript",
"prefix": "jfcom",
"body": [
"import React from 'react'",
"// import PropTypes from 'prop-types'",
"import { Text, View } from 'react-native'",
"import styles from './index.styled'",
"",
"const $1Component = () => (",
" <View style={styles.view}>",
" <Text>$1Component </Text>",
" </View>",
")",
"",
"// $1Component.propTypes = {",
" //",
"// }",
"",
"export default $1Component",
""
],
"description": "Jeff's Component"
},
"Jeff's HOC Component": {
"scope": "javascript",
"prefix": "jfcomh",
"body": [
"import React from 'react'",
"// import PropTypes from 'prop-types'",
"import { Text, View } from 'react-native'",
"import hoc from './hoc'",
"import styles from './index.styled'",
"",
"const $1 = () => (",
" <View style={styles.view}>",
" <Text>$1</Text>",
" </View>",
")",
"",
"// $1.propTypes = {",
" //",
"// }",
"",
"export default hoc($1)",
""
],
"description": "Jeff's HOC Component"
},
"Jeff's HOC": {
"scope": "javascript",
"prefix": "jfhoc",
"body": [
"import React, { useState, useEffect } from 'react'",
"// import PropTypes from 'prop-types'",
"import { connect } from 'react-redux'",
"// import * as actions from '../../actions'",
"",
"const hoc = ($1Container) => {",
" const $1Hoc = (props) => {",
" const [something, setSomething] = useState(false)",
"",
" useEffect(() => {",
" setSomething(true)",
" }, [])" ,
"",
" return (",
" <$1Container",
" {...props}",
" something={something}",
" />",
" )",
" }",
"",
" // $1Hoc.propTypes = {",
" // ",
" // }",
"",
" return $1Hoc",
"}",
"",
" //const mapStateToProps = ({ }) => ({",
" // ",
" //})",
"",
" //const mapDispatchToProps = {",
" // ",
" //}",
"",
" export default ($1Container) =>",
" connect(/*mapStateToProps, mapDispatchToProps*/)(",
" hoc($1Container)",
" )",
"",
],
"description": "Jeff's HOC"
},
"Jeff's Stylesheet": {
"scope": "javascript",
"prefix": "jfss",
"body": [
"import { StyleSheet } from 'react-native'",
"",
"export default StyleSheet.create({",
" view: {",
" flex: 1",
" },",
"})",
""
],
"description": "Jeff's Stylesheet"
}
}
@algera
Copy link
Author

algera commented Aug 28, 2020

Updated to functional component syntax with React hooks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment