VSCode user snippet to generate useState for React?
Asked Answered
U

2

20

I'm trying to create a VS code user snippet for useState()

Currently I have

  "use state": {
    "prefix": "us",
    "body": [
      "const [$1, set${1/(.*)/${1:/upcase}/}] = useState($2);",
      "$3"
    ],
    "description": "creates use state"
  },

When I enter 'foo' at $1 (position 1) I get:

const [foo, setFOO] as useState()

However I would like to get:

const [foo, setFoo] as useState()

How do I change my snippet to work this way?

Unintelligent answered 2/10, 2019 at 23:14 Comment(1)
Useful snippet!!Tod
T
25

You just need to change your transform to capitalize like:

"const [$1, set${1/(.*)/${1:/capitalize}/}] = useState($2);",

Tetrastich answered 19/10, 2019 at 2:46 Comment(2)
As per this comment, in case you're wondering why the 'set' part isn't capitalized, you have to press tab for the capitalization to happen :)Witless
Tab twice, in my experienceBarbey
C
0

You need to remove the "*", this character transforms all others to uppercase, without it, you will leave only the first uppercase.

  "prefix": "us",
  "body": [
    "const [$1, set${1/(.)/${1:/upcase}/}] = useState($2);",
    "$3"
   ],
  "description": "creates use state"
},
Cleavland answered 25/7, 2023 at 10:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.