Skip to content

Instantly share code, notes, and snippets.

@yojona
yojona / usePeerData
Created August 29, 2020 21:47
usePeerData - PeerJS for data
import { useState, useEffect, useCallback } from 'react';
import Peer from 'peerjs';
const usePeer = ({ id, host, port, path, onOpen, onConnection, onDisconnection, onClose, onError, onMessage }) => {
const [peer, setPeer] = useState();
const [peerId, setPeerId] = useState();
const [connection, setConnection] = useState();
const [message, setMessage] = useState();
const onPeerOpen = useCallback((current) => {