useEffect(() => {
setGamesList(nfl_games)
const nflGamesSubscription = supabase
.from('nfl_games')
.on('*', (payload) => {
handleGameUpdate(payload)
})
.subscribe()
const handleGameUpdate = (gameUpdate) => {
const changedGameKey = gameUpdate.old.GameKey
const updatedGames = games.map(game => game.GameKey === changedGameKey ? gameUpdate.new : game)
setGames(updatedGames)
}
return () => {
supabase.removeSubscription(nflGamesSubscription)
}
}, [nfl_games, gamesList])
useEffect(() => {
setGamesList(nfl_games)
const nflGamesSubscription = supabase
.from('nfl_games')
.on('*', (payload) => {
handleGameUpdate(payload)
})
.subscribe()
const handleGameUpdate = (gameUpdate) => {
const changedGameKey = gameUpdate.old.GameKey
const updatedGames = games.map(game => game.GameKey === changedGameKey ? gameUpdate.new : game)
setGames(updatedGames)
}
return () => {
supabase.removeSubscription(nflGamesSubscription)
}
}, [nfl_games, gamesList])