From 5ee6e4db8b9f8f4e57b8fe706630392bed9173d5 Mon Sep 17 00:00:00 2001 From: Daniel Castillo Date: Mon, 6 Jan 2025 09:33:01 -0500 Subject: [PATCH] feat: update useFirstVisit hook #25 --- snippets/js.code-snippets | 17 ++++++++--------- snippets/ts.code-snippets | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/snippets/js.code-snippets b/snippets/js.code-snippets index 6881d5c..405ce7c 100644 --- a/snippets/js.code-snippets +++ b/snippets/js.code-snippets @@ -647,22 +647,21 @@ "useFirstVisit": { "prefix": "useFirstVisit", "body": [ - "import { useState, useEffect } from 'react';", + "import { useState } from 'react';", "", "export const useFirstVisit = () => {", " const [isFirstVisit, setIsFirstVisit] = useState(false);", "", - " useEffect(() => {", - " const firstVisit = localStorage.getItem('firstVisit');", + " const firstVisit = localStorage.getItem('firstVisit');", "", - " if (firstVisit === null) {", - " localStorage.setItem('firstVisit', 'false');", - " setIsFirstVisit(true);", - " }", - " }, []);", + " if (firstVisit === null) {", + " localStorage.setItem('firstVisit', 'true');", + " setIsFirstVisit(true);", + " }", "", " return isFirstVisit;", - "};" + "};", + "" ], "description": "React hook to detect if it is the user's first visit" }, diff --git a/snippets/ts.code-snippets b/snippets/ts.code-snippets index 933b083..1288c0a 100644 --- a/snippets/ts.code-snippets +++ b/snippets/ts.code-snippets @@ -707,22 +707,21 @@ "useFirstVisit": { "prefix": "useFirstVisit", "body": [ - "import { useState, useEffect } from 'react';", + "import { useState } from 'react';", "", "export const useFirstVisit = (): boolean => {", " const [isFirstVisit, setIsFirstVisit] = useState(false);", "", - " useEffect(() => {", - " const firstVisit = localStorage.getItem('firstVisit');", + " const firstVisit = localStorage.getItem('firstVisit');", "", - " if (firstVisit === null) {", - " localStorage.setItem('firstVisit', 'false');", - " setIsFirstVisit(true);", - " }", - " }, []);", + " if (firstVisit === null) {", + " localStorage.setItem('firstVisit', 'true');", + " setIsFirstVisit(true);", + " }", "", " return isFirstVisit;", - "};" + "};", + "" ], "description": "React hook to detect if it is the user's first visit" },