Home / Function/ reducer() — ui Function Reference

reducer() — ui Function Reference

Architecture documentation for the reducer() function in use-toast.ts from the ui codebase.

Entity Profile

Dependency Diagram

graph TD
  02f056a2_d671_2934_e3a8_495b9d22c323["reducer()"]
  bba373ff_472d_b9de_12be_a7a606cb2977["use-toast.ts"]
  02f056a2_d671_2934_e3a8_495b9d22c323 -->|defined in| bba373ff_472d_b9de_12be_a7a606cb2977
  23a8ce30_00a5_617f_ac96_6badbe20ecf5["dispatch()"]
  23a8ce30_00a5_617f_ac96_6badbe20ecf5 -->|calls| 02f056a2_d671_2934_e3a8_495b9d22c323
  d66b6217_4be0_312d_7d3d_7269ff9b6feb["addToRemoveQueue()"]
  02f056a2_d671_2934_e3a8_495b9d22c323 -->|calls| d66b6217_4be0_312d_7d3d_7269ff9b6feb
  style 02f056a2_d671_2934_e3a8_495b9d22c323 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

deprecated/www/registry/new-york/hooks/use-toast.ts lines 77–130

export const reducer = (state: State, action: Action): State => {
  switch (action.type) {
    case "ADD_TOAST":
      return {
        ...state,
        toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT),
      }

    case "UPDATE_TOAST":
      return {
        ...state,
        toasts: state.toasts.map((t) =>
          t.id === action.toast.id ? { ...t, ...action.toast } : t
        ),
      }

    case "DISMISS_TOAST": {
      const { toastId } = action

      // ! Side effects ! - This could be extracted into a dismissToast() action,
      // but I'll keep it here for simplicity
      if (toastId) {
        addToRemoveQueue(toastId)
      } else {
        state.toasts.forEach((toast) => {
          addToRemoveQueue(toast.id)
        })
      }

      return {
        ...state,
        toasts: state.toasts.map((t) =>
          t.id === toastId || toastId === undefined
            ? {
                ...t,
                open: false,
              }
            : t
        ),
      }
    }
    case "REMOVE_TOAST":
      if (action.toastId === undefined) {
        return {
          ...state,
          toasts: [],
        }
      }
      return {
        ...state,
        toasts: state.toasts.filter((t) => t.id !== action.toastId),
      }
  }
}

Subdomains

Called By

Frequently Asked Questions

What does reducer() do?
reducer() is a function in the ui codebase, defined in deprecated/www/registry/new-york/hooks/use-toast.ts.
Where is reducer() defined?
reducer() is defined in deprecated/www/registry/new-york/hooks/use-toast.ts at line 77.
What does reducer() call?
reducer() calls 1 function(s): addToRemoveQueue.
What calls reducer()?
reducer() is called by 1 function(s): dispatch.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free