Lesson 72/100

Tutorials React.js Tutorial

SignalR — Complete Guide

SignalR — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of React.js Tutorial on Toolliyo Academy.

On this page

React.js Tutorial · Lesson 72 of 100

SignalR

Beginner ✓Intermediate ✓AdvancedProfessional

Advanced · 3 — Production skills · ~18 min read · Module 8: Full-Stack & Real-Time

Introduction

This is advanced material: SignalR. It is what teams use on live products. Read the example carefully and try changing one line at a time to see what happens. SignalR is Microsoft library for real-time server push — WebSockets with fallbacks. @microsoft/signalr client connects from React to ASP.NET Core hubs. Live dashboards, chat, and notifications need server-initiated updates, not polling every 5 seconds.

Frontend and backend are separate programs that talk over HTTP. React is the frontend; your API is the backend.

When will you use this?

Use when your React app must talk to a real backend or show live updates.

  • React frontends talk to .NET, Node, or Java APIs — fetch and auth are daily tasks.
  • Live chat and stock tickers use WebSockets or SignalR with React state.

Real-world: live order alerts for sellers

Flipkart seller hub uses SignalR hub — new order event pushes to React state, toast appears without polling.

Production-style code

import * as signalR from '@microsoft/signalr';

function useOrderAlerts(onNewOrder) {
  useEffect(() => {
    const conn = new signalR.HubConnectionBuilder()
      .withUrl('/hubs/orders')
      .withAutomaticReconnect()
      .build();
    conn.on('NewOrder', onNewOrder);
    conn.start();
    return () => { conn.stop(); };
  }, [onNewOrder]);
}

function SellerDashboard() {
  const [orders, setOrders] = useState([]);
  useOrderAlerts(order => setOrders(prev => [order, ...prev]));
  return <OrderFeed orders={orders} />;
}

What happens in production: Real-time dashboards for .NET backends often use SignalR — natural fit with React SPAs.

Lesson example (start here)

Copy this smaller example first. Once it works, compare it with the real-world code above.

import * as signalR from '@microsoft/signalr';

const connection = new signalR.HubConnectionBuilder()
  .withUrl('/hubs/notifications')
  .withAutomaticReconnect()
  .build();

connection.on('ReceiveMessage', msg => setMessages(m => [...m, msg]));
await connection.start();

Line-by-line walkthrough

CodeWhat it means
import * as signalR from '@microsoft/signalr';Imports code from React or another file so you can use it here.
const connection = new signalR.HubConnectionBuilder()Part of the SignalR example — read it together with the lines before and after.
.withUrl('/hubs/notifications')Part of the SignalR example — read it together with the lines before and after.
.withAutomaticReconnect()Part of the SignalR example — read it together with the lines before and after.
.build();Part of the SignalR example — read it together with the lines before and after.
connection.on('ReceiveMessage', msg => setMessages(m => [...m, msg]));Defines a function — often a component or event handler.
await connection.start();Part of the SignalR example — read it together with the lines before and after.

How it works (big picture)

  • Hub on ASP.NET Core sends ReceiveMessage.
  • React listens and updates state.
  • AutomaticReconnect handles dropped WiFi.

Do this on your computer

  1. Set up Hub on ASP.NET Core backend.
  2. npm install @microsoft/signalr
  3. Start connection in useEffect with cleanup stop().
  4. Read the real-world section and name which part of the app uses this topic.
  5. Run the example locally and confirm the same behavior in the browser.
  6. Change one value in the example (text, initial state, or URL) and predict what will happen before you save.

Experiments — try changing this

  • Change text or labels in the example and save — watch the browser update.
  • Break the code on purpose (remove a bracket), read the error message, then fix it.
  • Open React DevTools (browser extension) while running SignalR and inspect component props/state.

Remember

SignalR = real-time hub for .NET + React. useEffect for connect/disconnect. Show connection status to users.

Common questions

SignalR vs raw WebSocket?

SignalR adds reconnect, fallbacks, and hub routing on ASP.NET.

How long should I spend on SignalR?

Until you can explain it in your own words and run the example without looking at the answer. Beginners often need 30–60 minutes per new hook or routing topic; setup lessons may take one afternoon.

What if I get stuck on SignalR?

Re-read the line-by-line walkthrough, check the browser console for red errors, and compare your code character-by-character with the example. Search the exact error text — someone else had it too.

Where is SignalR used in real jobs?

See the real-world section above — the same pattern appears in LMS, banking, e-commerce, and SaaS products. Interviewers ask you to explain it using one concrete example from your project or this lesson.

Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

React.js Tutorial
Course syllabus

React.js Tutorial

Module 1: React Basics & Setup
Module 2: Props, Events & Lists
Module 3: Forms & Hooks
Module 4: Routing & Data
Module 5: State & Authentication
Module 6: Architecture & React 19
Module 7: Performance
Module 8: Full-Stack & Real-Time
Module 9: Testing & Deployment
Module 10: ShopCart Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details