Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indicate that promise messages may be functions, fixes #106 #117

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

BenJenkinson
Copy link
Contributor

  • Define the types for the toast.promise options to better indicate that they can accept a function in the same way that toast.success and the other methods can.
  • Add example to the documentation since a custom dismiss button seems to be a popular request.

Example

This already works in plain JS, but now it also works in TypeScript.

toast.promise(myPromise, {
  loading: "Loading",
  success: (data) => (toast) =>
    (
      <div>
        <span>Successfully saved ${data.name}</span>
        <button type="button" onClick={() => toast.dismiss(t.id)}>
           Custom dismiss button in a promise toast
        </button>
      </div>
    ),
  error: (err) => `This just happened: ${err.toString()}`,
});

- Define the types for the `toast.promise` options to better indicate that they can accept a function in the same way that `toast.success` and the other methods can.
- Add example to the documentation since a custom dismiss button seems to be a popular request.
@vercel
Copy link

vercel bot commented Aug 26, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/timo/react-hot-toast/4eFWeXm2C77BrtbHuRRkp7AeRYQ7
✅ Preview: https://react-hot-toast-git-fork-benjenkinson-dismiss-prom-089eca-timo1.vercel.app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant