Skip to content

Commit 7e29c46

Browse files
committed
remove onChange from LocalState initializer
1 parent 10b463f commit 7e29c46

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

Sources/SwiftUISupport/Components/LocalState.swift

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import SwiftUI
1414
VStack {
1515
LocalState(
1616
initial: ComponentState(),
17-
onChange: { print($0) }
1817
) { state in
1918
TextField("A", text: state.a)
2019
TextField("B", text: state.b)
@@ -24,29 +23,22 @@ import SwiftUI
2423
}
2524
```
2625
*/
27-
public struct LocalState<State: Equatable, Content: View>: View {
26+
public struct LocalState<State, Content: View>: View {
2827

2928
@SwiftUI.State var state: State
3029

3130
private let content: (Binding<State>) -> Content
3231

33-
private let onChange: (State) -> Void
34-
3532
public init(
3633
initial: State,
37-
onChange: @escaping (State) -> Void = { _ in },
3834
@ViewBuilder content: @escaping (Binding<State>) -> Content
3935
) {
40-
self.onChange = onChange
4136
self._state = .init(initialValue: initial)
4237
self.content = content
4338
}
4439

4540
public var body: some View {
4641
content($state)
47-
.onChange(of: state) { newValue in
48-
onChange(newValue)
49-
}
5042
}
5143

5244
}
@@ -129,8 +121,7 @@ struct BookState: View, PreviewProvider {
129121
var body: some View {
130122
VStack {
131123
LocalState(
132-
initial: ComponentState(),
133-
onChange: { print($0) }
124+
initial: ComponentState()
134125
) { state in
135126
TextField("A", text: state.a)
136127
TextField("B", text: state.b)

0 commit comments

Comments
 (0)