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
Source: stackoverflow.com
Related Query
- export react hook by changing its signature
- How to check if state default boolean false is changing to true with React Hook useEffect
- Support callback for changing another field value when using React Hook Form validation
- React <Switch> is not getting updated or changing its state
- Changing img src with React Hook that has a set onClick event
- I am trying to use the react hook useContext() but its not working
- Why does setState Hook from React is rendering twice even not changing the state?
- React hook changing the state variable of wrong component when file input
- Export function/method from react use effect / hook
- React table sorting is not consistent its keep changing back to default state
- Wrap a React hook and retain its types
- pass setState from parent to its child component using React Hook
- React Testing Library: How to test a component that requires the useState hook from its parent?
- When I click cancel button in react why the page is reloading and why its path also changing in react?
- React - how to make an export component private to its directory?
- React does not export its components via ES6 so IntelliJ throws warnings
- react - copy state to local variable without changing its value
- Can I export React Hook function to UI component, and trigger it?
- api data not changing when url_slug is changing in react hook
- Problems in highlighting a row of a table when one of its cell is hovered, using React hook useState?
- React changing state in Parent , does render calls for all its children and sub-children as iteration?
- React state data changing on its own
- How to save the position of an element after dragging and changing its position in react js
- react hook for submit button not changing data
- Custom react hook with useState always resetting to its initial value
- In react hook state is not retaining its previous state
- How can I re-trigger a custom hook inside my react component, when its states have not changed?
- React hook error when changing size of rendered array
- handleSubmit react hook form do not working, its do not execute onSumbmit
- How to properly export a component from a React custom hook and a function to control it?
More Query from same tag
- Update Redux State & Then Get The Updated State In Same Instance
- Sending update request to update a profile getting undefined in server side
- React passing props cannot read property of undefined
- Changing State of a Component by Input from children
- How to test for types on react components and props
- No 'Access-Control-Allow-Origin' header in some chrome version
- Display saved text onclick in React.js
- How do I pass MySQL query results back to renderer from Electron "main" process?
- Overlapping routes in react-router
- React Manage Multiple Audios on Same Page and play one at a time using function based components
- Fetch API not posting to Node.js server (body is empty)
- React useState cause double rendering
- "this" keyword with multiple objects
- How to get the value of the checkbox lable in material-ui?
- Redux is not updating initialState
- ReactJS + Material UI weird behaviour
- Call a function from a class in another file
- Getting env variables to an NGNIX react kubernetes pod
- why is form not submitting when using create-react-app?
- How to disable React's "Warning: Unknown prop"?
- Passing selected option value by user in remove button: React
- While doing an event handling exercise why didn't I need to use the componentDidMount() method?
- How can I apply styling to Material UI tabs in React?
- How can I concatenate index to a function in Reactjs elements
- Can we integrate react component into Aurelia project?
- Multiple routes from single page in NextJs
- An icon of fontawesome doesn't apeear in react code
- Next.js: Skipping generating static sites at build time (instead: only at runtime, as getStaticProps has no data in build phase)
- setState(..., callback) calls callback before state has been set
- high order function in react(useState())