Skip to content

Toast component action #2467

Answered by segunadebayo
officialankan asked this question in Q&A
Discussion options

You must be logged in to vote

You can add it like so

// 2. Design the toast component
function Toast(props) {
  const machineProps = {
    ...props.toast,
    parent: props.parent,
    index: props.index,
  }
  const service = useMachine(toast.machine, machineProps)
  const api = toast.connect(service, normalizeProps)

  return (
    <div {...api.getRootProps()}>
      <h3 {...api.getTitleProps()}>{api.title}</h3>
      <p {...api.getDescriptionProps()}>{api.description}</p>
      <button onClick={api.dismiss}>Close</button>
      {props.toast.action && (
        <button
          onClick={() => {
            props.toast.action.onClick?.()
          }}
        >
          {props.toast.action.label}
        </button>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by segunadebayo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants