Last active
September 24, 2022 17:09
-
-
Save grrrlikestaquitos/47aa962204f2f528257b7be5d7518f8a to your computer and use it in GitHub Desktop.
SwiftUI: Higher Order Component Syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Declaring ContainerView as a HOC | |
struct ContainerView<C: View> : View { | |
let childView: C | |
init(_ childView: () -> (C)) { | |
self.childView = childView() | |
} | |
var body: some View { | |
childView | |
} | |
} | |
// Using ContainerView by passing SwiftUI's Text Component | |
ContainerView { | |
Text("Hello There I'm a child component!") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment