Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nxp769 opened this issue Oct 20, 2023 · 3 comments
Closed

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

nxp769 opened this issue Oct 20, 2023 · 3 comments

Comments

@nxp769
Copy link

nxp769 commented Oct 20, 2023

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} </Alert> ); }), }} 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:

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
Copy link
Author

nxp769 commented Oct 20, 2023

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
Copy link
Author

nxp769 commented Oct 20, 2023

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

@nxp769 nxp769 closed this as completed Oct 20, 2023
@nxp769
Copy link
Author

nxp769 commented Oct 20, 2023

Issue resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant