Topic: How can you fire Toast with out a button and onClick?

Manamapps free asked 4 years ago


Expected behavior fire toast when when props change in useEffect Actual behavior Doesnt open the notification. the function "notify()" runs only in onClick buttons Resources (screenshots, code snippets etc.)

const Notification = (props) => {

useEffect(() => { console.log('Use Effect Notification', props) // setTimeout(() => { notify('info', 'top-right')

// }, 1000);

}, [props]);

const notify = (type, position = 'top-right') => { console.log(type) return () => { switch (type) { case 'info': toast.info('Hi! I am an info message!', { autoClose: 3000, position: position }); break; case 'success': toast.success('Hi! I am a success message', { position: position }); break; case 'warning': toast.warn('Hi! I am a warning message', { position: position }); break; case 'error': toast.error('Well, I am an error message', { position: position }); break; default: } }; } return ( <> {/* /} {/ Top right */} ); }


Jakub Chmura staff commented 4 years ago

Try to fire the notify function on the onChange event at the same place where you changing the prop. This solution should work.

If you get lost and can't implement my solution, send a larger piece of code. I can't help you based on your code because it doesn't say much about this matter.If

Best, Kuba



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Opened

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: 4.24.0
  • Device: desktop
  • Browser: chrome
  • OS: windows 10
  • Provided sample code: No
  • Provided link: No
Tags