0

I need your help. I want to initialized a Toast instance with React.userRef, but without launch it, because I want to use that Ref Id to update any Toast type, and I don't know which Toast type (info, error, success) happens first.

For example:

const alertToast = React.useRef(null)
alertToast.current = toast('')

  const infoAlert = (message) =>
    toast.update(alertToast.current, {
      render: message,
      type: toast.TYPE.INFO,
      autoClose: 1500,
    })
  const successAlert = () =>
    toast.update(alertToast.current, {
      render: 'Success!!',
      type: toast.TYPE.SUCCESS,
      autoClose: 2500,
    })
  const errorAlert = (code, message) =>
    toast.update(alertToast.current, {
      render: `Error with code: ${code} and message: ${message}`,
      type: toast.TYPE.ERROR,
      autoClose: false,
    })

But the line alertToast.current = toast('') always launch the Toast

Thanks for your help.

Raul
  • 465
  • 5
  • 16

0 Answers0