title: How can I run an action when a state changes?
body: <pre><code>enum SectionType: String, CaseIterable {
      case top = "Top"
      case best = "Best"
  }
  
  struct ContentView : View {
      @State private var selection: Int = 0
  
      var body: some View {
          SegmentedControl(selection: $selection) {
              ForEach(SectionType.allCases.identified(by: \.self)) { type in
                  Text(type.rawValue).tag(type)
              }
          }
      }
  }
  </code></pre>
  
  <p>How do I run code (e.g <code>print("Selection changed to \(selection)")</code> when the <code>$selection</code> state changes? I looked through the docs and I couldn't find anything.</p>