@ewb/reach-react
Version:
React Resource and Fetch stuff
19 lines (18 loc) • 695 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useSocketEvent = void 0;
const react_1 = require("react");
const ReachNamespaceContext_1 = require("./ReachNamespaceContext");
function useSocketEvent(event, fn) {
const socketConnection = react_1.useContext(ReachNamespaceContext_1.ReachNamespaceContext);
react_1.useEffect(() => {
if (socketConnection && event && fn) {
const ret = socketConnection.on(event, fn);
return () => {
ret.off(event, fn);
};
}
}, [socketConnection, event, fn]);
return socketConnection;
}
exports.useSocketEvent = useSocketEvent;