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.
This should work:
"const [ ${1}, set${1/(.*)/${1:/capitalize}/} ] = useState()"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With