How to import SignalR in React Component?

后端 未结 4 664
谎友^
谎友^ 2020-12-30 10:02

I have used create-react-app to scaffold the initial react application.

My DashBoard component:

import React, { Co         


        
4条回答
  •  隐瞒了意图╮
    2020-12-30 10:06

    Check out SignalR no jQuery

    npm i -D signalr-no-jquery
    import { hubConnection } from 'signalr-no-jquery';
    
    const connection = hubConnection('http://[address]:[port]', options);
    const hubProxy = connection.createHubProxy('hubNameString');
    
    // set up event listeners i.e. for incoming "message" event
    hubProxy.on('message', function(message) {
        console.log(message);
    });
    
    // connect
    connection.start({ jsonp: true })
      .done(function(){ console.log('Now connected, connection ID=' + connection.id); })
      .fail(function(){ console.log('Could not connect'); });
    

    https://www.npmjs.com/package/signalr-no-jquery

提交回复
热议问题