We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Toast could not get dynamic content

Thread ID:

Created:

Updated:

Platform:

Replies:

146443 Aug 4,2019 10:19 AM UTC Aug 8,2019 03:10 AM UTC React - EJ 2 2
loading
Tags: Toast
safronco safronco
Asked On August 4, 2019 10:19 AM UTC

Hi
After set content property in React Toast with state, but it dosen`t show dynamic content. my dynamic content fetched with signalr.everything is ok.console.log(this.state.message) printed correct value but in Toast content dosen`t appeared.



import React, { Component } from 'react';
import { ToastComponent } from '@syncfusion/ej2-react-notifications';
import * as signalR from '@aspnet/signalr';


class Notification extends React.Component {

    constructor() {
        super(...arguments);
        this.position = { X: 'Right', Y: 'Top' }
        this.state = { message:null}

    }

    toastCreated() {
        this.toastInstance.show({ timeOut: 0 })
        
    }
    
    componentDidMount() {
        const notifConn = new signalR.HubConnectionBuilder().withUrl("/notif").build();

        notifConn.on("ReceiveMessage",(msg) => {
            this.setState({ message: msg });
        });
        notifConn.start().then(function () {
            notifConn.invoke("SendNotification");
            
        }).catch(function (er) {
            console.log(er.toString());
        });
        
    }
    

    render() {
        return (
            <div>
                <ToastComponent 
                   //id='toast_target'
                   ref={toast => this.toastInstance = toast}
                   title={this.state.message}
                   content={this.state.message}
                   position={this.position}    
                   showCloseButton
                   created={this.toastCreated = this.toastCreated.bind(this)}
                />
            </div>
               );
    }
}




export default Notification;



Narayanasamy Panneer Selvam [Syncfusion]
Replied On August 5, 2019 12:41 PM UTC

Hi Safronco,

Thanks for contacting us.

Currently we are working on your issue, we will get back to you with further details shortly.
 
 
Regards, 
Narayanasamy P. 


Narayanasamy Panneer Selvam [Syncfusion]
Replied On August 8, 2019 03:10 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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon