react-toastify
react-toastify copied to clipboard
Add update toast type when `toast.promise` resolves
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