{ "Output HTML Tag": { "prefix": "tag", "body": [ "var heading = \"<${h2}>Heading</${h2}>\";", "var body = \"<${p}>I wandered lonely as a cloud.</${p}>\";", "document.querySelector(\"#${id}\").innerHTML = heading + body;", "$0" ], "description": "Outputs HTML via JavaScript." } }
JSX
"Output HTML Tag": { "prefix": "tag", "body": [ "class ${Component} extends React.Component {", "\trender() {", "\t\treturn (", "\t\t\t<Fragment>", "\t\t\t\t<${h1}>Heading</${h1}>", "\t\t\t\t<${p}>I wandered lonely as a cloud.</${p}>" "\t\t\t</Fragment>", "\t\t)", "\t}", "}", "$0" ], "description": "Outputs HTML via JSX." } }
As before, just start typing out the trigger text (in this case tag
) and you’ll see the relevant code snippet for the type of file you’re currently editing.
Congratulations, you’ve now graduated to the world of polymorphic code snippets!
This approach to developing code snippets is very efficient and can save you from having to remember lot’s of different snippet triggers. Now you only need to remember just a single trigger for snippets that perform a common task.
What’s more, you can create as many of these polymorphic code snippets as you like!
Get set up with LogRocket's modern error tracking in minutes:
- Visit https://logrocket.com/signup/ to get an app ID
-
Install LogRocket via npm or script tag.
LogRocket.init()
must be called client-side, not server-side$ npm i --save logrocket // Code: import LogRocket from 'logrocket'; LogRocket.init('app/id');
// Add to your HTML: <script src="https://cdn.lr-ingest.com/LogRocket.min.js"></script> <script>window.LogRocket && window.LogRocket.init('app/id');</script>
- (Optional) Install plugins for deeper integrations with your stack:
- Redux middleware
- NgRx middleware
- Vuex plugin