---
title: "onReceive(_:perform:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/onreceive(_:perform:)"
---

# onReceive(_:perform:)

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

## Declaration

```swift
nonisolated func onReceive<P>(_ publisher: P, perform action: @escaping (P.Output) -> Void) -> some View where P : Publisher, P.Failure == Never

```

## Parameters

- `publisher`: The publisher to subscribe to.
- `action`: The action to perform when an event is emitted by publisher. The event emitted by publisher is passed as a parameter to action.

## Return Value

Return Value A view that triggers action when publisher emits an event.

## See Also

### Responding to data changes

- [onChange(of:initial:_:)](swiftui/view/onchange(of:initial:_:).md)
