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

Support when navigating to another page #560

Open
randerso21 opened this issue Apr 12, 2023 · 2 comments
Open

Support when navigating to another page #560

randerso21 opened this issue Apr 12, 2023 · 2 comments

Comments

@randerso21
Copy link

import { useNavigate } from "react-router-dom";

const navigate = useNavigate();
const handleCreate = useCallback(
(e: any) => {
createName(props.name, props.description)
.then((response) => {
navigate("/");
enqueueSnackbar("Successfully added a new name", {variant: "success"});
})
.catch((error) => {
enqueueSnackbar(error.message.toString(), {variant: "error"});
});
},
[props.description, props.name, navigate]
);

I see the snackbar when I get the error, but when I am successful I do not see the snackbar

@iamhosseindhv
Copy link
Owner

@randerso21 I'd need a minimal reproduction example to be able to help

@randerso21
Copy link
Author

Does this work?
File name is Hist.tsx

`import React from "react";
import { Helmet } from "react-helmet";
import { useNavigate } from "react-router-dom";
import Button from '@mui/material/Button';
import { SnackbarProvider, useSnackbar } from 'notistack';

function Hist() {
const navigate = useNavigate();
const { enqueueSnackbar } = useSnackbar();

const handleClick = () => {
navigate("/");
enqueueSnackbar('I love snacks.');
};

const handleClickVariant = (message: string, variant: any) => () => {
enqueueSnackbar(message, { variant });
};

return (



<title>"TESTING"</title>


TESTING


<React.Fragment>
  <Button onClick={handleClick}>Show snackbar</Button>
  <Button onClick={handleClickVariant("This is a SUCCESS", 'success')}>Show success snackbar</Button>
  <Button onClick={handleClickVariant("This is an ERROR", 'error')}>Show error snackbar</Button>
</React.Fragment>


</div>

);
}
function Hist2() {
return (



);
}

export default Hist2;
`

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

2 participants