EDIT — For those unfamiliar with React, the second “setter” will always begin with set.
I've got the following vim snippet that I'm using (with coc-snippets) for React:
snippet STATE_HOOK "useState hook" b
const [${1:state}, set${1:`!v expand('%:t:r')`}] = useState($2)
endsnippet
This could be used to quickly create the following (incorrect) code:
const [color, setcolor] = useState("green");
The problem is that the setcolor
needs to be camelcased, like this: setColor
How would one write this snippet so that the expanded input is capitalized? I've looked at another library's implementation of this, and it looks like this:
const [$1, set${1/\w+\s*/\u$0/g}] = useState(${3:''})${0:;}
However, this provides me with the following:
const [color, set\ucolor] = useState("green");
from How can you capitalize this word in VIM snippet?
No comments:
Post a Comment