hosseinmd / react-signalr

MIT License
43 stars 14 forks source link

Allow #6

Closed RobertSasak closed 2 years ago

RobertSasak commented 3 years ago

Provider should accept ReactNode instead of JSX.Element. This will allow to create nice general purpose component.

Typescript error

Type 'ReactNode' is not assignable to type 'Element'.
  Type 'undefined' is not assignable to type 'Element'.ts(2322)

Usage

import React from 'react';
import { createSignalRContext } from 'react-signalr';

import { useAuth } from './Auth';

const url = 'https://api.test.dev/hub';

const SignalRContext = createSignalRContext();

const SignalR: React.FC = ({ children }) => {
    const { token } = useAuth();

    return (
        <SignalRContext.Provider connectEnabled={!!token} accessTokenFactory={() => token} dependencies={[token]} url={url}>
            {children} // Workaround {children as JSX.Element}
        </SignalRContext.Provider>
    );
};

export default SignalR;
hosseinmd commented 3 years ago

I will do it soon, thank you.

hosseinmd commented 2 years ago

Fixed in v0.2.13