0

I want to create a custom function snippet like this :

const handle = () => {

}

But when I put it in visual studio code javascript snippets JSON file it gets red underline which means the format is not correct :

javascript.json

How can I put a custom function snippet with no error in visual studio code user snippets ?

1
  • 1
    first read the doc pages of VSC, maybe the squiggles will also tell you what the problem is Commented Jul 15, 2021 at 7:29

2 Answers 2

1

You can't have newlines in JSON strings. Instead use \n (or \r\n on windows). But VS code expects you to pass different lines as different strings. So, you can change your body to

[
     "const handle = () => {",
     "$0",
     "}"
]

$0 is where your cursor will be if you accept the hint. The pressing tab will take you to $1, $2, $3, ....

Sign up to request clarification or add additional context in comments.

Comments

1

JSON body is an array so that you can provided multiple lines (array items) comma separated.

"React Function": {
  "prefix" : "f",
  "body": [
     "const handle = () => {",
     "$0",
     "}"
  ],
  "description": "some description"
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.