Cache follows in localstorage

This commit is contained in:
James Grugett 2022-07-16 14:58:24 -05:00
parent bae55828a1
commit 1edc1993e1

View File

@ -5,7 +5,16 @@ export const useFollows = (userId: string | null | undefined) => {
const [followIds, setFollowIds] = useState<string[] | undefined>()
useEffect(() => {
if (userId) return listenForFollows(userId, setFollowIds)
if (userId) {
const key = `follows:${userId}`
const follows = localStorage.getItem(key)
if (follows) setFollowIds(JSON.parse(follows))
return listenForFollows(userId, (follows) => {
setFollowIds(follows)
localStorage.setItem(key, JSON.stringify(follows))
})
}
}, [userId])
return followIds