onPreferenceChange(_:perform:)
Adds an action to perform when the specified preference key’s value changes.
Declaration
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
keychanges. Theactionclosure passes the new value as its parameter.
Return Value
A view that triggers action when the value for key changes.