<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 6.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/onPreferenceChange(_:perform:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE18onPreferenceChange_7performQrqd__m_y5ValueQyd__ctAA0E3KeyRd__SQAGRQlF"
  },
  "title" : "onPreferenceChange(_:perform:)"
}
-->

# onPreferenceChange(_:perform:)

Adds an action to perform when the specified preference key’s value
changes.

```
nonisolated func onPreferenceChange<K>(_ key: K.Type = K.self, perform action: @escaping (K.Value) -> Void) -> some View where K : PreferenceKey, K.Value : Equatable
```

## Parameters

`key`

The key to monitor for value changes.

`action`

The action to perform when the value for `key` changes. The
`action` closure passes the new value as its parameter.

## Return Value

A view that triggers `action` when the value for `key`
changes.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)