How to create your own custom VS code snippets.

Code snippets can be very useful and can potentially increase productivity and reduce input errors.

With snippets we can insert commonly used code blocks and can create boilerplate templates saving us keystrokes.

Snippets in VS code are written in JS…


This content originally appeared on DEV Community and was authored by Rahul Soni

Code snippets can be very useful and can potentially increase productivity and reduce input errors.

With snippets we can insert commonly used code blocks and can create boilerplate templates saving us keystrokes.

Snippets in VS code are written in JSON and to create your own custom snippet.

Snippets can be configured through Preferences (Ctrl + Shift + P) -> Configure User Snippets.

It should look something like this.
snippets

Snippets can be configured for every file or specific languages in their JSON file.

Every snippet has 3 main properties

  1. prefix - Shortcut by which it will be called.
  2. body - Actual code to be inserted
  3. description - Description of the code

This is a custom snippet with prefix arfc for generating a React component. It works in following steps.

  1. Imports React
  2. Creates a functional React component with placeholder name functionName
  3. Returns an empty div
  4. exports the component arfc

It will yield this code.

arfc result

Another one of my favorite is
fetch data

The ftcData will inject this piece of code

fetch api

A very good tool to generate custom snippets is this Snippet Generator, which works for Sublime and Atom as well.

A very popular VS code extension for JavaScript, React, React-Native, Redux snippets
vs code extension


This content originally appeared on DEV Community and was authored by Rahul Soni


Print Share Comment Cite Upload Translate Updates
APA

Rahul Soni | Sciencx (2021-10-14T16:57:52+00:00) How to create your own custom VS code snippets.. Retrieved from https://www.scien.cx/2021/10/14/how-to-create-your-own-custom-vs-code-snippets/

MLA
" » How to create your own custom VS code snippets.." Rahul Soni | Sciencx - Thursday October 14, 2021, https://www.scien.cx/2021/10/14/how-to-create-your-own-custom-vs-code-snippets/
HARVARD
Rahul Soni | Sciencx Thursday October 14, 2021 » How to create your own custom VS code snippets.., viewed ,<https://www.scien.cx/2021/10/14/how-to-create-your-own-custom-vs-code-snippets/>
VANCOUVER
Rahul Soni | Sciencx - » How to create your own custom VS code snippets.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/14/how-to-create-your-own-custom-vs-code-snippets/
CHICAGO
" » How to create your own custom VS code snippets.." Rahul Soni | Sciencx - Accessed . https://www.scien.cx/2021/10/14/how-to-create-your-own-custom-vs-code-snippets/
IEEE
" » How to create your own custom VS code snippets.." Rahul Soni | Sciencx [Online]. Available: https://www.scien.cx/2021/10/14/how-to-create-your-own-custom-vs-code-snippets/. [Accessed: ]
rf:citation
» How to create your own custom VS code snippets. | Rahul Soni | Sciencx | https://www.scien.cx/2021/10/14/how-to-create-your-own-custom-vs-code-snippets/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.