🍫 React Snackbar Alert

Custom Timeout

By default, a snackbar is removed after 3 seconds. A custom timeout can be specified in one of two ways:

  • Setting the timeout prop on the SnackbarProvider for all snackbars
  • Setting the timeout property on the object passed to createSnackbar for a specific snackbar
import React from 'react';

import { SnackbarProvider, wrapComponent } from 'react-snackbar-alert';

export default function CustomTimeoutExample() {
  return (
    <SnackbarProvider timeout={5000}>
      <Container />
    </SnackbarProvider>
  );
}

const Container = wrapComponent(function({ createSnackbar }) {
  function showSnackbar() {
    createSnackbar({
      message: 'Hello Snackbar!'
    });
  }

  return (
    <div>
      <button onClick={showSnackbar}>Show Snackbar</button>
    </div>
  );
});