score:3

Accepted answer

you can define a custom hook that wraps the usesnackbar hook as follow:

import { snackbarprovider, usesnackbar } from 'notistack';

export const usetoast = () => {
  const { enqueuesnackbar, closesnackbar } = usesnackbar();
  return { addtoast: enqueuesnackbar, closetoast: closesnackbar };
};

export const snackbarprovider = toastprovider;

you can learn more about building custom hooks on the documentation: https://reactjs.org/docs/hooks-custom.html


Related Query

More Query from same tag