Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
export react hook by changing its signature

I want to change a hook name and its return values while exporting them. Here is my use case. I want to use notistack api to show some toasts in my application. However, because I don't like the name snackbar I want to change it to toast. Here is how I start doing it:

export { SnackbarProvider as ToastProvider, useSnackbar as useToast } from 'notistack';

But I can't manage to change the name of the variables returned from the useSnackbar hook.

const { enqueueSnackbar, closeSnackbar } = useSnackbar();

should be

const { addToast, closeToast } = useToast();

how can I achieve this?

thank you.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!