Skip to content

Instantly share code, notes, and snippets.

@Daltonic
Created September 1, 2023 09:36
Show Gist options
  • Save Daltonic/bf6c176e52493ca256faa241ebe2e810 to your computer and use it in GitHub Desktop.
Save Daltonic/bf6c176e52493ca256faa241ebe2e810 to your computer and use it in GitHub Desktop.
Dapp Votes
import { initCometChat, checkAuthState } from '@/services/chat'
import { useEffect } from 'react'
import { globalActions } from '@/store/globalSlices'
import { useDispatch } from 'react-redux'
const CometChatNoSSR = () => {
const { setCurrentUser } = globalActions
const dispatch = useDispatch()
useEffect(() => {
setTimeout(async () => {
if (typeof window !== 'undefined') {
await initCometChat()
checkAuthState().then((user) => {
dispatch(setCurrentUser(JSON.parse(JSON.stringify(user))))
})
}
}, 500)
}, [dispatch, setCurrentUser])
return null
}
export default CometChatNoSSR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment