Skip to content

Commit 9b55441

Browse files
committed
Resolving some hook dependencies
1 parent 306861f commit 9b55441

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

lib/hooks/useArticleReactions.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useState } from 'react';
1+
import { useCallback, useEffect, useState } from 'react';
22

33
import { Reactions } from '../types';
44
import { fetcher } from '../fetcher';
@@ -32,6 +32,13 @@ export default function useArticleReactions(slug) {
3232
}
3333
);
3434

35+
const getReactionsFromLocalStorage = useCallback(() => {
36+
if (typeof window !== 'undefined') {
37+
return JSON.parse(localStorage.getItem(slug)) || initialReactionState;
38+
}
39+
return null;
40+
}, [slug]);
41+
3542
useEffect(() => {
3643
setHydrated(true);
3744
}, []);
@@ -176,12 +183,12 @@ export default function useArticleReactions(slug) {
176183
setReactionsToLocalStorage(updatedReactionState);
177184
}
178185

179-
function getReactionsFromLocalStorage() {
180-
if (typeof window !== 'undefined') {
181-
return JSON.parse(localStorage.getItem(slug)) || initialReactionState;
182-
}
183-
return null;
184-
}
186+
// function getReactionsFromLocalStorage() {
187+
// if (typeof window !== 'undefined') {
188+
// return JSON.parse(localStorage.getItem(slug)) || initialReactionState;
189+
// }
190+
// return null;
191+
// }
185192

186193
function setReactionsToLocalStorage(reactions) {
187194
if (typeof window !== 'undefined') {

0 commit comments

Comments
 (0)