Reputation: 3836
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 :
How can I put a custom function snippet with no error in visual studio code user snippets ?
Upvotes: 0
Views: 629
Reputation: 89
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, ....
Upvotes: 1
Reputation: 4625
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"
}
Upvotes: 1