-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Snackbar] Add imperative methods to display them directly #18098
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@jiangyh1024 I'm 💯 onboard with you, I think that an imperative API makes a lot of sense. We recommend the usage of notistack for this problem, for now. Follow the discussion with @leMaik in #17762 for more details. I think that we should snooze this problem for a good 6 months to see how people react. |
I manage to solve a similar problem with |
Is that true? You could write it like this, no? export default function MyComponent() {
const [snackbar, setSnackbar] = useState<{ message: string; duration: number }>();
const onClose = () => setSnackbar(undefined);
return (
<>
<Button
onClick={() => {
setSnackbar({
message: "My primary message for the user.",
duration: 3000,
});
}}
>
Trigger
</Button>
<Portal>
<Snackbar
open={snackbar != null}
autoHideDuration={snackbar?.duration}
onClose={onClose}
message={snackbar?.message}
></Snackbar>
</Portal>
</>
);
} |
@kasperpeulen I think that your example precisely surfaces the issue. This is not enough. What happens if two Snackbar component tries to display a message? What's do we gain by writing this boilerplate, can't it be abstracted? |
Maybe you want to check out the imperative Snackbar library that I built. |
Summary 💡
Support imperative calls for the sake of simplicity.
Examples 🌈
Motivation 🔦
Without such support, a developer has to set up a global event emitter system. It's cumbersome and tedious.
Benchmark
The text was updated successfully, but these errors were encountered: