Connection with signalr

Hi
Is there any exmaple for connection Syncfusion React Toast in order to get dynamic contents with signalr asp.net core?
Thanks...

1 Reply

NP Narayanasamy Panneer Selvam Syncfusion Team August 8, 2019 03:12 AM UTC

Hi Safronco, 
 
Good day to you. 
 
By default, we cannot modify the content dynamically for existing displaying toasts. The dynamically changed content will be shown on notify the next toasts. So, we suggest you to hide the previous toast and show the next toast after setState. 
  
Please find the below code for your reference. 
 
 Chat.js 
constructor(props) { 
super(props); 
 
this.state = { 
    message: '', 
}; 
componentDidMount = () => { 
    const nick = window.prompt('Your name:', 'John'); 
 
    const hubConnection = new HubConnection('http://localhost:5000/chat'); 
 
    this.setState({ hubConnection, nick }, () => { 
        ………….. 
        this.state.hubConnection.on('sendToAll', (nick, receivedMessage) => { 
            this.setState({ message: receivedMessage }); // Change the toast content using state 
            this.toastObj.hide(); // You can hide the toast 
            this.toastObj.show(); // You can show the toast 
        }); 
    }); 
}; 
 
create = () => { 
    this.toastObj.show({ timeOut: 0 }); 
} 
 
<ToastComponent ref={ (toast) => { this.toastObj = toast; } } content = { this.state.message } id = 'toast_default' created = { this.create.bind(this) } > </ToastComponent> 
  
We have created sample for an ASP.NET core signalr with the react toast component. 
  
Please find the below steps to run the above sample. 
·       Navigate inside of AspNetCoreSignalR_React.Client folder and enter ‘npm install’. 
·       Start the client app by entering ‘npm start’. 
·       Run the AspNetCoreSignalR_React.Server project. 
 
If the above solution doesn’t meet your requirement, kindly send the below details. 
·       Have any reason on using static toasts with dynamic content update? 
 

Regards,
 
Narayanasamy P. 


Loader.
Up arrow icon