mui / mui/material-ui

[Snackbar] Add a simple notification method(), showing global Snackbars (especially for reducers)

Open
#31,300 4 comments 6 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the latest version
Summary 💡
Current scenerio 😯

Currently, in MUI we only have snackbars that should be used in such a way that can be rendered as HTML (JSX syntax) i.e

<Snackbar
  open={open}
  autoHideDuration={6000}
  onClose={handleClose}
  message="Note archived"
  action={action}
/>

OR

<Alert severity="error">This is an error message!</Alert>

New and required behavior 🤔

But what if we have to generate a snackbar from within the reducer i.e

  name: "userMatches",
  initialState: {
    matchesData: {
      matches: [],
    },
  },
  reducers: {
    getMatches: (state, { payload }) => {
      state.loading = true;
    },
    getMatchesSuccess: (state, { payload }) => {
      state.loading = false;
      state.matchesData.matches = payload.matchData;
    },
    getMatchesFailed: (state, { payload }) => {
      state.loading = false;
       👉 // notification.error(payload.message);
       👉 notification.success(payload.message);

    },
}
})

So currently we are not able to do that in reducers and have to install another package, or have to create the global and to do a bunch of stuff to achieve the functionality

Sumup 🙌

A simple calling method to show the notification or snackbar for some specific task, a method that can be called from anywhere of the application

Examples 🌈

No response

Motivation 🔦

We can check this scenario working here, as Antd implemented it

https://ant.design/components/notification/

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.

Research direction

Start by reading the existing Snackbar and Alert usage, then compare the requested reducer call pattern with Ant Design's notification API. Done means a globally callable notification method can show success and error snackbars from application code, including reducers, without requiring each caller to render a Snackbar.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.