emilkowalski / sonner

An opinionated toast component for React.

Home Page:https://sonner.emilkowal.ski

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to add description in a promise

Noname968 opened this issue Β· comments

Describe the feature πŸ“:

How to add description to a promise success or error.

Hi,
I just look through the code and the return types for both success and error is defined as React.ReactNode | string. Given that you wish to display a header field that is followed by a description, you may attempt building your structure by enclosing it within an element and returning it as a response. The promise functionality does not have its own description field.

Example:

type ResponseType = {
  header: string;
  description: string;
}

toast.promise<ResponseType>(
  Promise.resolve({
    header: "Notification",
    description: "Test Description",
  }),
  {
    loading: "Loading...",
    success: (data: ResponseType) => {
      return (
        <div>
          <div className="font-semibold">{data.header}</div>
          <p>{data.description}</p>
        </div>
      );
    },
    error: "Error"
  }
);

I hope this answers your query πŸ˜‡