Skip to content

Instantly share code, notes, and snippets.

@glowiep
Last active February 3, 2024 21:03
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 glowiep/6949391f98e902f8299c2ccf4e69a416 to your computer and use it in GitHub Desktop.
Save glowiep/6949391f98e902f8299c2ccf4e69a416 to your computer and use it in GitHub Desktop.
React Visual Studio Code JavaScript Snippets for component, useState, useEffect, and useReducer
{
"React Component": {
"prefix": "react",
"body": ["import React from \"react\"", "", "function ${1:ComponentName}() {", " return (", " <>", " $2", " </>", " )", "}", "", "export default ${1:ComponentName}"],
"description": "React Component"
},
"useState Hook": {
"prefix": "use",
"body": [
"const [$1, set${1/(.)/${1:/upcase}/}] = useState();"
],
"description": "Creates a useEffect expression"
},
"useEffect Hook": {
"prefix": "use",
"body": [
"useEffect(() -> {",
"$1",
"}, []);"
],
"description": "Creates a useEffect expression"
},
"useReducer Hook": {
"prefix": "use",
"body": ["const ${1:INITIAL_STATE} = {", "", "}", "", "function reducer(state, action) {", " switch (action.type) {", " case \"${4:NameMe}\":", " // Do something here", " return", " }", "}", "", "const [${2:state}, ${3:dispatch}] = useReducer(reducer, $1)"],
"description": "Creates a useReducer expression"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment