22

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?

1
  • Useful snippet!! Commented Oct 20, 2022 at 3:43

2 Answers 2

27

You just need to change your transform to capitalize like:

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

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

2 Comments

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 :)
Tab twice, in my experience
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"
},

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.