Skip to content

Commit

Permalink
improved useRoom hook
Browse files Browse the repository at this point in the history
  • Loading branch information
dmotz committed Aug 12, 2024
1 parent 8eaaafb commit 1ba4259
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,15 @@ import {useEffect, useRef} from 'react'

export const useRoom = (roomConfig, roomId) => {
const roomRef = useRef(joinRoom(roomConfig, roomId))
const lastRoomIdRef = useRef(roomId)

useEffect(() => {
roomRef.current = joinRoom(roomConfig, roomId)
if (roomId !== lastRoomIdRef.current) {
roomRef.current.leave()
roomRef.current = joinRoom(roomConfig, roomId)
lastRoomIdRef.current = roomId
}

return () => roomRef.current.leave()
}, [roomConfig, roomId])

Expand Down

0 comments on commit 1ba4259

Please sign in to comment.