react-toastify icon indicating copy to clipboard operation
react-toastify copied to clipboard

Add update toast type when `toast.promise` resolves

Open alexandredev3 opened this issue 1 year ago • 5 comments

Now the type prop accepts a function and receives the data returned from the promise. It's similar to the render prop.

example:

const promise = () => Promise.resolve({ errors: 'error' });

toast.promise(promise, {
  success: {
    render: ({ data }) => data.errors ? 'Promise rejected' : 'Promise resolved',
    type: (data) => data.errors ? 'error' : 'success',
  },
  error: 'Promise rejected'
});

There's no need to work around using toast.update anymore if the promise resolves with an error.

resolves https://github.com/fkhadra/react-toastify/issues/819

alexandredev3 avatar Oct 09 '22 13:10 alexandredev3