How to redraw a child view in SwiftUI?

I have a ContentView that has a state variable "count". When its value is changed, the number of stars in the child view should be updated.

struct ContentView: View {
  @State var count: Int = 5
   
  var body: some View {
    VStack {
      Stepper("Count", value: $count, in: 0...10)
      StarView(count: $count)
    }
    .padding()
  }
}

struct StarView: View {
  @Binding var count: Int
   
  var body: some View {
    HStack {
      ForEach(0..<count) { i in
        Image(systemName: "star")
      }
    }
  }
}

I know why the number of stars are not changed in the child view, but I don't know how to fix it because the child view is in a package that I cannot modify. How can I achieve my goal only by changing the ContentView?

So I understand the StarView is much more complex in the package than what you showed here ?

Otherwise, why not recreate a StarView2() ?

When running your code, I get the error: ForEach<Range, Int, Image> count (7) != its initial count (5). ForEach(_:content:) should only be used for constant data. Instead conform data to Identifiable or use ForEach(_:id:content:) and provide an explicit id!

I changed with

    ForEach(0..<count, id: \.self) { i in
        Image(systemName: "star")
    }

And now the number of starts change when I tap on `+ / -

Note: I also changed to see the number in count:

      Stepper("Count \(count)", value: $count, in: 0...10)

I don't get any error when running it. I'm using XCode 12.5.1. How to close the thread? This is my first post here and I don't know how to close it.

How to redraw a child view in SwiftUI?
 
 
Q