ramonchang

Untitled

Jan 17th, 2021
945
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import {useState, useEffect} from "react"
  2. import * as PusherPushNotifications from "@pusher/push-notifications-web"
  3. import Pusher from 'pusher-js';
  4.  
  5. function App() {
  6.   const [data, updateData] = useState(sampleData)
  7.   const [total, updateTotal] = useState({message: sampleData[0]})
  8.   const [subStatus, updateSubStatus] = useState("subscribe")
  9.  
  10.   const pusher = new Pusher("b691171de5f8ac605664", {
  11.     cluster: "mt1"
  12.   });
  13.   const channel = pusher.subscribe('votes');
  14.  
  15.   channel.bind('vote-event', function(dataFromServer) {
  16.     updateData(data =>{
  17.      
  18.       data.splice(Number(dataFromServer.message[11]), 1, dataFromServer.message)
  19.       const arr = [...data]
  20.       return arr
  21.     }
  22.     )
  23.    
  24.     updateTotal(dataFromServer)
  25.    
  26.    
  27.   });
RAW Paste Data