API
To show or hide the Toast programmatically, bind the visible property of the Toast to a state property. After that, change the latter property, and the Toast will appear or disappear.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { Toast } from 'devextreme-react/toast';
- import { Button } from 'devextreme-react/button';
- class App extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- isVisible: false
- };
- this.onClick = this.onClick.bind(this);
- this.onHiding = this.onHiding.bind(this);
- }
- onClick() {
- this.setState({
- isVisible: true
- });
- }
- onHiding() {
- this.setState({
- isVisible: false
- });
- }
- render() {
- return (
- <div>
- <Toast
- visible={this.state.isVisible}
- message="Connection problem"
- type="error"
- onHiding={this.onHiding}
- />
- <Button
- text="Show the Toast"
- onClick={this.onClick}
- />
- </div>
- );
- }
- }
- export default App;
User Interaction
Because the Toast is supposed to notify a user when something happens, it cannot be invoked from the UI. However, it may be hidden from the UI in many different ways. To decide which of them are available to the user, specify the following properties.
Property | Description |
---|---|
closeOnClick | Hides the Toast when a user clicks/presses it. |
hideOnOutsideClick | Hides the Toast when a user clicks/presses outside of it. |
closeOnSwipe | Hides the Toast when a user swipes it out of the screen. |
Events
To execute certain commands before or after the Toast was shown/hidden, handle the showing, shown, hiding or hidden event. If the event handling function is not going to be changed during the lifetime of the UI component, assign it to the corresponding onEventName property:
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { Toast } from 'devextreme-react/toast';
- import { Button } from 'devextreme-react/button';
- class App extends React.Component {
- onShowing(e) {
- // Handler of the 'showing' event
- }
- onShown(e) {
- // Handler of the 'shown' event
- }
- onHiding(e) {
- // Handler of the 'hiding' event
- }
- onHidden(e) {
- // Handler of the 'hidden' event
- }
- render() {
- return (
- <Toast ...
- onShowing={this.onShowing}
- onShown={this.onShown}
- onHiding={this.onHiding}
- onHidden={this.onHidden}
- />
- );
- }
- }
- export default App;
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.