Skip to content

Commit

Permalink
Finsh feature/15
Browse files Browse the repository at this point in the history
  • Loading branch information
dlcastillop authored Nov 26, 2024
2 parents e5a4e82 + 330ff1a commit 65ecb82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
18 changes: 9 additions & 9 deletions snippets/js.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -562,27 +562,27 @@
"useFavicon": {
"prefix": "useFavicon",
"body": [
"import { useEffect, useState } from 'react';",
"import { useState } from 'react';",
"",
"export const useFavicon = () => {",
" const [faviconUrl, setFaviconUrl] = useState('');",
" const [faviconUrl, setFaviconUrl] = useState(",
" document.querySelector(`link[rel~='icon']`)?.href",
" );",
"",
" useEffect(() => {",
" const changeFavicon = (newFavicon) => {",
" let link = document.querySelector(`link[rel~='icon']`);",
"",
" if (!link) {",
" link = document.createElement('link');",
" link.type = 'image/x-icon';",
" link.rel = 'icon';",
" document.head.appendChild(link);",
" }",
"",
" link.href = faviconUrl;",
" }, [faviconUrl]);",
"",
" const changeFavicon = (newFavicon) => setFaviconUrl(newFavicon);",
" link.href = newFavicon;",
" setFaviconUrl(newFavicon);",
" };",
"",
" return changeFavicon;",
" return { faviconUrl, changeFavicon };",
"};"
],
"description": "React hook to change the page favicon"
Expand Down
20 changes: 10 additions & 10 deletions snippets/ts.code-snippets
Original file line number Diff line number Diff line change
Expand Up @@ -616,27 +616,27 @@
"useFavicon": {
"prefix": "useFavicon",
"body": [
"import { useEffect, useState } from 'react';",
"import { useState } from 'react';",
"",
"export const useFavicon = (): ((newFavicon: string) => void) => {",
" const [faviconUrl, setFaviconUrl] = useState<string>('');",
"export const useFavicon = () => {",
" const [faviconUrl, setFaviconUrl] = useState(",
" (document.querySelector(`link[rel~='icon']`) as HTMLLinkElement)?.href",
" );",
"",
" useEffect(() => {",
" const changeFavicon = (newFavicon: string) => {",
" let link = document.querySelector(`link[rel~='icon']`) as HTMLLinkElement;",
"",
" if (!link) {",
" link = document.createElement('link');",
" link.type = 'image/x-icon';",
" link.rel = 'icon';",
" document.head.appendChild(link);",
" }",
"",
" link.href = faviconUrl;",
" }, [faviconUrl]);",
"",
" const changeFavicon = (newFavicon: string) => setFaviconUrl(newFavicon);",
" link.href = newFavicon;",
" setFaviconUrl(newFavicon);",
" };",
"",
" return changeFavicon;",
" return { faviconUrl, changeFavicon };",
"};"
],
"description": "React hook to change the page favicon"
Expand Down

0 comments on commit 65ecb82

Please sign in to comment.