iamhosseindhv / notistack

Highly customizable notification snackbars (toasts) that can be stacked on top of each other
https://notistack.com
Other
3.9k stars 299 forks source link

How to trigger "close Snack bar" from custom snack bar component. #586

Closed nxp769 closed 11 months ago

nxp769 commented 11 months ago

Expected Behavior

I am passing a custom snack bar component using "Components" prop to SnackbarProvider. I want to access snackbar closing function from my custom snack bar component. `<SnackbarProvider Components={{ success: React.forwardRef((props, ref) => { console.log("========>", props) return ( <Alert ref={ref} onClose={() => {}} key={props.id} severity="success"

{props.message} ); }), }} maxSnack={3} ` I want to close snack bar when onClose is triggered from Alert Component.

Current Behavior

I tried to log the props from the callback of success, but I do not see any function to close snackbar

Steps to Reproduce

Link:

1. 2. 3. 4.

Context

I want to close snack bar when onClose is triggered from Alert Component.

Your Environment

Tech Version
Notistack v3.0.1
React 18.2.0
Browser chorme
etc.
nxp769 commented 11 months ago

Tried passing in enqueSnackBar hook it worked.

enqueueSnackbar('Loaded not Scheduled Work Orders!', { variant: 'success', anchorOrigin: { horizontal: 'right', vertical: 'bottom' }, closeSnackbar, });

It would be great if it's possible to include by default in the props.

nxp769 commented 11 months ago

Finally figured out import { closeSnackbar } from "notistack".

nxp769 commented 11 months ago

Issue resolved