title: Replacing SwiftUI Button with a custom Button
body: <p>I would like to extend the SwiftUI.Button so that i can add a type prop and have that type change to different types of my theme buttons. But I am new to Swift and I can't figure out how to have my label and action props be generic.</p>
  <p>In other words if i do this</p>
  <pre><code>import SwiftUI
  
  struct Button: View {
      var type: String = &quot;&quot;
      var action = {}
      var label = {
          Text(&quot;Button&quot;)
      }
      
      var body: some View {
          ZStack(content: {
              SwiftUI.Button(action: action, label: label)
          })
      }
      
      
  }
  </code></pre>
  <p>it limits the closure to only allow for label to return text()</p>
  <p>how can this be done</p>
  <p>also any suggestions on how i should to alter the &quot;alterations&quot; done to the button based on the type.</p>
  <p>NOTE:
  someone downvoted this because it is similar to <a href="https://stackoverflow.com/questions/60995278/custom-button-in-swiftui-list">button style</a> query from another user however it is not.</p>
  <p>that solution is for simply adding pre-made styles to the default SwiftUI.button struct and that's not my goal.</p>
  <p>I'm attempting to extend SwiftUI.Button with a type property that can be passed and will set the styling based that input.</p>
  <p>Although they share the same result they are not accomplishing the same goal. My solution will offer a dynamically styled component which can be used throughout the project. without the need of trailing <code>.buttonStyle(BlueButtonStyle())</code></p>