Skip to content

Commit

Permalink
add multiple callbacks to componentDidMount
Browse files Browse the repository at this point in the history
  • Loading branch information
bmcmahen committed Jun 6, 2019
1 parent 3d7a77a commit 580228d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ComponentDidMount.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,42 @@ struct ChildCounter : View {
}

```

You can attach multiple `onAppear` and `onDisappear` callbacks in your `body` function:

```swift
struct Counter : View {
@State var count = 0

func increment () {
count += 1
}

func mount () {
print("Child mount")
}

func unmount () {
print("Child unmount")
}

func parentMount () {
print("parent mount")
}


var body: some View {
VStack {
Button(action: increment) {
Text("Increment")
}
if count < 10 || count > 12 {
ChildCounter(count: count)
.onAppear(perform: mount)
.onDisappear(perform: unmount)
}
}
.onAppear(perform: parentMount)
}
}
```

0 comments on commit 580228d

Please sign in to comment.