How to import SignalR in React Component?

后端 未结 4 698
谎友^
谎友^ 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:29

    What I figured out Signalr has dependency on jQuery. For some reason import $ from 'jquery' doesn't set window.jQuery. That's why need to do it explicitly.

    I solved the issue this way:

    import React, { Component } from 'react';
    import { Link } from 'react-router-dom';
    import $ from 'jquery';
    window.jQuery = $;
    require('signalr');
    
    class Dashboard extends Component {
       // .....   
    }
    
    export default Dashboard;
    

提交回复
热议问题