onPreferenceChange

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

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

Declaration

React
compose().onPreferenceChange(
  key: string,
  options: {
    perform: (arg0: any) => void;
  }
)
Swift
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*string

    The key to monitor for value changes.

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

Return value

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

See also

More in Events and lifecycle.