Skip to content

Commit

Permalink
Fix useS snippet in UltiSnips/javascript_react
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Farzat07 authored and lpil committed Mar 25, 2021
1 parent 44b467f commit 67e506c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion UltiSnips/javascript_react.snippets
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
global !p
# Capitalize the first letter without affecting the rest of the letters
def capitalize_first(word):
if(word):
word = word[0].upper() + word[1:]
return word
endglobal

# Functional components
snippet rfc "react functional component" b
import React, {useState} from "react"
Expand All @@ -14,7 +22,7 @@ export default $4`!p snip.rv = snip.basename`
endsnippet
# React Hooks
snippet useS "useState Hook" b
const [${1}, set`!p snip.rv=t[1].title()`] = useState(${3:"${4}"})
const [${1}, set`!p snip.rv=capitalize_first(t[1])`] = useState(${3:"${4}"})
endsnippet
snippet useE "useEffect Hook" b
useEffect(() => {
Expand Down

0 comments on commit 67e506c

Please sign in to comment.