GithubHelp home page GithubHelp logo

Comments (3)

mfrachet avatar mfrachet commented on June 1, 2024

I should definitely investigate this 😅 . Sorry for the delay, I'm quite busy at work these days :D

from server-push-hooks.

dmozzoni avatar dmozzoni commented on June 1, 2024

No problem, I worked around it by creating an alternative provider component, which is basically a copy of yours but I instead import SocketIOClient from the package since you thankfully export it already, and then separated the useRef and the socket.io connection calls. Not saying it's the best solution, but it served my purposes.

import React, {useRef} from 'react';
import io from 'socket.io-client';
// import { SocketIOContext } from "./context";
import {SocketIOContext} from 'use-socketio';

export interface ISocketIOProviderProps {
  url: string;
  opts?: SocketIOClient.ConnectOpts;
}

export const SocketIOProvider: React.FC<ISocketIOProviderProps> = ({
  url,
  opts,
  children
}) => {
  // const socketRef = useRef(io(url, opts || {}));
  const socketRef = useRef<any>();
  if (!socketRef.current) socketRef.current = io(url, opts || {});

  return (
    <SocketIOContext.Provider value={socketRef.current}>
      {children}
    </SocketIOContext.Provider>
  );
};

from server-push-hooks.

mfrachet avatar mfrachet commented on June 1, 2024

Thanks to your snippet I've been able to fix this support quickly. Thank you so much for your help! It should be fixed and available in the 2.0.1 versions 😊 . Let me know if it works for you!

Have a great day :)

from server-push-hooks.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.