mui / mui/material-ui

[Snackbar] Add imperative methods to display them directly

Open
#18,098 7 comments 37 reactions 1 assignee View on GitHub

@ZeeshanTamboli is already working on this.

Since May 5, 2022.

priority: important scope: toast type: new feature
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Summary 💡

Support imperative calls for the sake of simplicity.

Examples 🌈

import { useSnackbar } from '@material-ui/core';

function MyComponent() {
  const snackbar = useSnackbar();

  return (
    <Button
      onClick={() => {
        snackbar({
          message: "My primary message for the user.",
          duration: 3000,
          variant: 'success',
        });
      }}
    >
      Trigger
    </Button>
  );
}
import { ConfigProvider } from '@material-ui/core';

<ConfigProvider snackbar={{ maxItems: 3 }} />

Motivation 🔦

Without such support, a developer has to set up a global event emitter system. It's cumbersome and tedious.

Benchmark

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.