mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
remove SnackBar component | improve Provider
This commit is contained in:
1 parent
8ec2a4769d
commit
82adc9497b
2 files changed
+5
-13
No files matched your search
@@ -1,9 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
|
|
||||||
export const SnackBar = ({ children }) => {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<p>{children}</p>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,7 @@ import React, { createContext, useState, useEffect, useMemo, useCallback } from
|
|||||||
import Alert from './Alert';
|
import Alert from './Alert';
|
||||||
import { makeStyles } from '@material-ui/core/styles';
|
import { makeStyles } from '@material-ui/core/styles';
|
||||||
import { Snackbar } from '@material-ui/core';
|
import { Snackbar } from '@material-ui/core';
|
||||||
|
import { ISnackbar } from '../interface/InterfaceUI';
|
||||||
|
|
||||||
const useStyles = makeStyles(() => ({
|
const useStyles = makeStyles(() => ({
|
||||||
alert: {
|
alert: {
|
||||||
@@ -28,7 +29,7 @@ function SnackbarProvider({ children }) {
|
|||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}, [alertIdx])
|
}, [alertIdx])
|
||||||
|
|
||||||
const addAlert = useCallback((content) => setAlerts((alerts) => [content, ...alerts]), []);
|
const addAlert = useCallback((message, type) => setAlerts((alerts) => [{message, type}, ...alerts]), []);
|
||||||
|
|
||||||
const value = useMemo(() => ({ addAlert }), [addAlert]);
|
const value = useMemo(() => ({ addAlert }), [addAlert]);
|
||||||
|
|
||||||
@@ -36,10 +37,10 @@ function SnackbarProvider({ children }) {
|
|||||||
<SnackbarContext.Provider value={value}>
|
<SnackbarContext.Provider value={value}>
|
||||||
<>
|
<>
|
||||||
{children}
|
{children}
|
||||||
{alerts.map((alert) => (
|
{alerts.map((alert: ISnackbar) => (
|
||||||
<div className={classes.alert}>
|
<div className={classes.alert}>
|
||||||
<Alert auto key={alert} severity="success" variant="filled">
|
<Alert auto key={alert} severity="success" variant={alert.type}>
|
||||||
{alert}
|
{alert.message}
|
||||||
</Alert>
|
</Alert>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Reference in new issue
Block a user