Created
January 17, 2022 19:20
-
-
Save lumenwrites/b7504eaa042a8cbe68a1cc5f3d799790 to your computer and use it in GitHub Desktop.
Pusher useEffect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useEffect(() => { | |
// Pusher.logToConsole = true | |
let pusher = new Pusher(process.env.NEXT_PUBLIC_PUSHER_KEY, { | |
cluster: process.env.NEXT_PUBLIC_PUSHER_CLUSTER, | |
}) | |
window.onbeforeunload = function () { | |
pusher.disconnect() | |
} | |
let channel = pusher.subscribe('story-engine') | |
channel.bind('place-card', function (data) { | |
// console.log('Received event', data) | |
setSlots((prev) => { | |
[some code for putting the broadcasted data into state] | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment