Cache follows in localstorage
This commit is contained in:
parent
bae55828a1
commit
1edc1993e1
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user