Having to re-write the same boilerplate code for a React component with StaticQuery
from Gatsby can get tiresome. Which is why I recently made a small snippet for VS Code in order to automate the process.
Go to File > Preferences > User Snippets
(Or Code > Preferences > User Snippets` on MacOS), choose JavaScript, and paste the following snippet inside of the curly braces:
JSON
\n\t\n
"Gatsby Static Query": {
"prefix": "gatstaq",
"body": [
"import React from 'react'",
"import { StaticQuery, graphql } from 'gatsby'\n",
"const ${1/(.*)/${1:/capitalize}/} = ({ data }) => (\n\t$0\n)\n",
"const ${1:page}Query = graphql\n",
"export default () => (\n\t<StaticQuery query={${1:page}Query} render={data => <${1/(.*)/${1:/capitalize}/} data={data} />} />\n)\n"
]
}
Originally posted on my blog: Gatsby StaticQuery Snippet for VS Code
Top comments (1)
Awesome, just what I needed! I suggest you could put it into a repo to share.