Skip to content

Commit

Permalink
feat: update useTitle template #10
Browse files Browse the repository at this point in the history
  • Loading branch information
dlcastillop committed Oct 27, 2024
1 parent 94a6e88 commit 1dd32fc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
*.vsix
.idea/
13 changes: 6 additions & 7 deletions snippets/js.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -1425,19 +1425,18 @@
"useTitle": {
"prefix": "useTitle",
"body": [
"import { useState, useEffect } from 'react';",
"import { useState } from 'react';",
"",
"export const useTitle = () => {",
" const [title, setTitle] = useState(document.title);",
"",
" useEffect(() => {",
" document.title = title;",
" }, [title]);",
"",
" const changeTitle = (newTitle) => setTitle(newTitle);",
" const changeTitle = (newTitle) => {",
" document.title = newTitle;",
" setTitle(newTitle);",
" }",
"",
" return { title, changeTitle };",
"};"
"};",
],
"description": "React hook to change the page title"
},
Expand Down
20 changes: 7 additions & 13 deletions snippets/ts.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -1551,24 +1551,18 @@
"useTitle": {
"prefix": "useTitle",
"body": [
"import { useState, useEffect } from 'react';",
"",
"interface UseTitleOutput {",
" title: string;",
" changeTitle: (newTitle: string) => void;",
"}",
"import { useState } from 'react';",
"",
"export const useTitle = (): UseTitleOutput => {",
"export const useTitle = () => {",
" const [title, setTitle] = useState<string>(document.title);",
"",
" useEffect(() => {",
" document.title = title;",
" }, [title]);",
"",
" const changeTitle = (newTitle: string) => setTitle(newTitle);",
" const changeTitle = (newTitle: string) => {",
" document.title = newTitle;",
" setTitle(newTitle);",
" }",
"",
" return { title, changeTitle };",
"};"
"};",
],
"description": "React hook to change the page title"
},
Expand Down

0 comments on commit 1dd32fc

Please sign in to comment.