# react-snackbar-toast

> Snackbar/Toast Component for react

Latest version **1.2.6** (published 2022-03-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-snackbar-toast
pnpm add react-snackbar-toast
yarn add react-snackbar-toast
bun add react-snackbar-toast
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.6 |
| Published | 2022-03-02 |
| First published | 2020-02-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 37.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Avinash Ganiga |
| Maintainers | mr_coder |
| Keywords | react-snackbar, react-toast, react, snackbar, alert, notification, message, toast, reactjs |

## Links

- npm: https://www.npmjs.com/package/react-snackbar-toast
- Repository: https://github.com/avinash-ganiga/react-snackbar-toast
- Homepage: https://github.com/avinash-ganiga/react-snackbar-toast#readme
- Issues: https://github.com/avinash-ganiga/react-snackbar-toast/issues
- npm.io page: https://npm.io/package/react-snackbar-toast

## Dependencies (2)

- [classnames](https://npm.io/package/classnames.md) ^2.2.6
- [react-transition-group](https://npm.io/package/react-transition-group.md) ^4.3.0

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 1.2.6 (latest) — 2022-03-02
- 1.2.4-beta.0 (beta) — 2022-03-02
- 1.2.5 — 2020-08-10
- 1.2.4 — 2020-08-10
- 1.2.2 — 2020-03-02
- 1.2.1 — 2020-03-02
- 1.2.0 — 2020-02-27
- 1.1.2 — 2020-02-27
- 1.1.1 — 2020-02-27
- 1.1.0 — 2020-02-27
- 1.0.1 — 2020-02-26
- 1.0.0 — 2020-02-21
- 0.4.2 — 2020-02-19
- 0.4.1 — 2020-02-19
- 0.4.0 — 2020-02-19
- … 9 more at https://npm.io/package/react-snackbar-toast/versions

## README

# React snackbar/toast component
Find demo [here](https://codesandbox.io/s/recursing-flower-0xrvz?fontsize=14&hidenavigation=1&theme=dark)
## Installation

```
npm install --save react-snackbar-toast
```

or

```
yard add react-snackbar-toast
```

## Usage

Wrap your application with SnackbarProvider

```
// App.js
import React from 'react'
import {SnackbarProvider} from 'react-snackbar-toast'
import MessageComponent from './MessageComponent'

export default function App() {
  return (
    <SnackbarProvider>
        <MessageComponent/>
    </SnackbarProvider>
  )
}
```

Then you can use useSnackbar() hook on any descendant functional component:

```
// MessageComponent.js
import React from 'react'
import useSnackbar from 'react-snackbar-toast'

export default function MessageComponent() {
  const {addToast} = useSnackbar()

  return (
    <div>
      <button onClick={() => addToast('Snackbar content')}>
        Click to open the Snackbar!
      </button>
    </div>
  )
}
```

if you are having class component then wrap your component withSnackbar()

```
import React from 'react'
import { withSnackbar } from 'react-snackbar-toast'
 
class SomeComponent extends React.Component {
  render() {
    const { addToast, removeAllToast } = this.props
 
    return (
      <div>
        <button onClick={() => addToast('This is the content of the Snackbar.')}>
          Click here to open the Snackbar.
        </button>
        <button onClick={removeAllToast}>
          Click here to remove all snackbars.
        </button>
      </div>
    )
  }
}
export default withSnackbar(SomeComponent)

```

These methods are are returned from useSnackbar() hook in array destructuring syntax:

```
const {addToast, removeToast, removeAllToast} = useSnackbar()
```

### addToast(node, [options])

```
    addToast('Hey')
    addToast('<b>Hey</b>')
    addToast('Hey', {autoDismiss: false, type: 'success'})
```

### removeToast(id)

Remove the particular snackbar with returned id from addToast.

```
    let toastId = addToast('Hey', {autoDismiss: false});
    removeToast(toastId)
```

### removeAllToast()

Remove all active snackbars.

```
    addToast('Hey', {autoDismiss: false});
    addToast('Hey', {autoDismiss: false});
    removeAllToast()
```
    

## Options

Options object can be passed to customize the Snackbar. This option can be passed with useSnackbar(node, options):

    autoDismissTime:(number) Used to give auto dismissal time for snackbar. By Default it is 3000ms.
                    addToast('Hey', {autoDismissTime: 10000});

    autoDismiss:(Boolean) To disable auto dismissal of snackbar.
                 addToast('Hey', {autoDismiss: false});

    icon:(string) To provide custom icon for snackbar. 
          addToast('Hey', {icon: 'http://www.img.com/img});

    type:(string) Two types 'success' and 'error'.
          addToast('Hey', {autoDismiss: false, type: 'success'})

    className:(string) adds the custom className to snackbar.
          addToast('Hey', {className: 'customClass'})

    closeButton:(Boolean) adds the close button to snackbar.
          addToast('Hey', {closeButton: true})

    closeIcon:(string) To provide custom icon to close button.
          addToast('Hey, How are you today?', {closeButton: true, closeIcon: 'http://www.img.com/img});
          
    component:(ReactNode) We can custom component for snackabr.
                addToast(<somecomponent/>)

    retry:(Function) To show retry button in snackbar.
            addToast('something wrong', {autoDismiss: false, type: 'error', retry: () => {//do retry here}} )

---
_Source: https://npm.io/package/react-snackbar-toast · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
