- Home
- Forum
- React - EJ 2
- Toast could not get dynamic content
Toast could not get dynamic content
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;
SIGN IN To post a reply.
2 Replies
NP
Narayanasamy Panneer Selvam
Syncfusion Team
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.
Thanks for contacting us.
Currently we are working on your issue, we will get back to you with further details shortly.
Regards,
Narayanasamy P.
NP
Narayanasamy Panneer Selvam
Syncfusion Team
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.
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
SS safronco safronco
- Aug 4, 2019 10:19 AM UTC
- Aug 8, 2019 03:10 AM UTC