Skip to content

Commit 67e506c

Browse files
Farzat07lpil
authored andcommitted
Fix useS snippet in UltiSnips/javascript_react
Previously, the .title() function was used to capitalize the first item. However, this function doesn't maintain the capitalization of letters in the middle. Therefore, a custom function was created to effectively convert camelCase to PascalCase.
1 parent 44b467f commit 67e506c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

UltiSnips/javascript_react.snippets

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
global !p
2+
# Capitalize the first letter without affecting the rest of the letters
3+
def capitalize_first(word):
4+
if(word):
5+
word = word[0].upper() + word[1:]
6+
return word
7+
endglobal
8+
19
# Functional components
210
snippet rfc "react functional component" b
311
import React, {useState} from "react"
@@ -14,7 +22,7 @@ export default $4`!p snip.rv = snip.basename`
1422
endsnippet
1523
# React Hooks
1624
snippet useS "useState Hook" b
17-
const [${1}, set`!p snip.rv=t[1].title()`] = useState(${3:"${4}"})
25+
const [${1}, set`!p snip.rv=capitalize_first(t[1])`] = useState(${3:"${4}"})
1826
endsnippet
1927
snippet useE "useEffect Hook" b
2028
useEffect(() => {

0 commit comments

Comments
 (0)