1- import { useCallback , useEffect , useState } from 'react' ;
1+ import { useEffect , useState } from 'react' ;
22
33import { Reactions } from '../types' ;
44import { fetcher } from '../fetcher' ;
@@ -32,13 +32,6 @@ 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-
4235 useEffect ( ( ) => {
4336 setHydrated ( true ) ;
4437 } , [ ] ) ;
@@ -55,7 +48,7 @@ export default function useArticleReactions(slug) {
5548 setHasClapped ( clapped ) ;
5649 setHasPartied ( partied ) ;
5750 }
58- } , [ getReactionsFromLocalStorage , hydrated ] ) ;
51+ } , [ hydrated , setReactionsToLocalStorage ] ) ;
5952
6053 useEffect ( ( ) => {
6154 setReactions ( data ) ;
@@ -183,12 +176,12 @@ export default function useArticleReactions(slug) {
183176 setReactionsToLocalStorage ( updatedReactionState ) ;
184177 }
185178
186- // function getReactionsFromLocalStorage() {
187- // if (typeof window !== 'undefined') {
188- // return JSON.parse(localStorage.getItem(slug)) || initialReactionState;
189- // }
190- // return null;
191- // }
179+ function getReactionsFromLocalStorage ( ) {
180+ if ( typeof window !== 'undefined' ) {
181+ return JSON . parse ( localStorage . getItem ( slug ) ) || initialReactionState ;
182+ }
183+ return null ;
184+ }
192185
193186 function setReactionsToLocalStorage ( reactions ) {
194187 if ( typeof window !== 'undefined' ) {
0 commit comments