# Snackbar

You can add the component on any page in the template. You need to follow the steps given below:&#x20;

**Step 1:** You need to create a state and functions to handle it's events. Also you need to add the code of snackbar in the page where you want to add the component. Please check the code snippet given below, we have added the snackbar in the Ecommerce Dashboard:

```
/**
 * Ecommerce Dashboard
 */

import React, { Component } from 'react'
...

export default class EcommerceDashboard extends Component {
    // Snackbar State
	state = {
		open: false,
	};

	// Snackbar Functions
	handleClick = () => {
		this.setState({ open: true });
	};

	handleClose = (event, reason) => {
		if (reason === 'clickaway') {
			return;
		}
		this.setState({ open: false });
	};
	render() {
		...
						// Snackbar Code
						<div>
							<Button variant="contained" color="primary" className="text-white mr-10 mb-10 d-inline-block" onClick={this.handleClick}>simple snackbar</Button>
							<Snackbar anchorOrigin={{ vertical: 'bottom', horizontal: 'left', }}
								open={this.state.open}
								autoHideDuration={6000}
								onClose={this.handleClose}
								message={<span id="message-id">Note archived</span>}
								action={[
									<Button variant="contained" key="undo" className="btn-danger btn-sm text-white" dense="true" onClick={this.handleClose}> UNDO </Button>,
									<IconButton key="close" aria-label="Close" color="inherit" onClick={this.handleClose} >
										<i className="zmdi zmdi-close"></i>
									</IconButton>,
								]}
							/>
						</div>
```

**Step 2:** Now Import the component from its parent library.

```
import Button from '@material-ui/core/Button';
import Snackbar from '@material-ui/core/Snackbar';
import IconButton from '@material-ui/core/IconButton';
```

We have given you an example of adding a simple snackbar on the Ecommerce Dashboard.

![](https://3423697845-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEnOfkACC-WsXr2rO7I%2F-Lbwk5o1imcj0MO1VWFB%2F-LbwkgoXpBezUIRy5Y3D%2FSelection_046.png?alt=media\&token=97ecc4f1-abce-434e-b7b9-f36bf3e69367)

![](https://3423697845-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEnOfkACC-WsXr2rO7I%2F-Lbwk5o1imcj0MO1VWFB%2F-LbwkiGfh_cK5U-t7nkR%2FSelection_045.png?alt=media\&token=ad9163f2-448d-4829-8eea-cc9260e9c539)

You can check some other layouts of snackbar below. For adding any of the below layout in the template, please check their relative code in the `src->routes->components->snackbar->component` folder.

![](https://3423697845-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEnOfkACC-WsXr2rO7I%2F-LbvP11UgKU4MlVzPa8h%2F-LbvVBBywIQYQxLAOY6T%2FScreenshot%202019-04-08%20at%2011.19.18%20AM.png?alt=media\&token=31fd8a9c-76a6-4643-b7e0-c9f0d08e7191)
