onReceive

Adds an action to perform when this view detects data emitted by the given publisher.

View ModifieriOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+onReceive(_:perform:) in SwiftUI

Declaration

React
compose().onReceive(
  publisher: { notification: string; } | { every: number; },
  options: {
    perform: (arg0: unknown) => void;
  }
)
Swift
nonisolated func onReceive<P>(
    _ publisher: P,
    perform action: @escaping (P.Output) -> Void
) -> some View
where P : Publisher, P.Failure == Never

Parameters

  • publisher*{ notification: string; } | { every: number; }

    The publisher to subscribe to.

  • options.perform*(arg0: unknown) => void

Return value

A view that triggers action when publisher emits an event.

See also

More in Events and lifecycle.