Using localStorage in Remix

import { useState } from 'react'

const Like = ({ storageKey, likes }) => {
    const [hasLiked, setHasLiked] = useState(false)

    setHasLiked(window.localStorage.getItem(storageKey) === 'true')
})
ReferenceError: window is not defined
import { useEffect, useState } from 'react'

const Like = ({ storageKey, likes }) => {
    const [hasLiked, setHasLiked] = useState(false)

    useEffect(() => {
        setHasLiked(window.localStorage.getItem(storageKey) === 'true')
    }, [storageKey])
})