Reputation: 335
I want to create VSCode snippet to quickly use React's useState. E.g. for a state open
const [open, setOpen] = useState()
I'm currently using
"const [ ${1}, set$1 ] = useState()"
But this gives me const [open, setopen] = useState()
. Note the lack of caps on open
.
I want to be able to just enter the state name open
, and have the snippet sort out the capitalization for setOpen
. I know I could use 2 variables, but I don't want to type it out twice since it'll always follow the pattern [foo, setFoo]
I know I can do transforms like ${1:/upcase}
, but this capitalizes the entire variable, not just the first letter.
Upvotes: 20
Views: 8438
Reputation: 1
You can hit tab after typing 'open' as answered here in the feature request answer by alDuncanson in feature request
Upvotes: 0
Reputation: 4805
This should work:
"const [ ${1}, set${1/(.*)/${1:/capitalize}/} ] = useState()"
Upvotes: 48