title: how i share state in this case for stateobjec
body: <p>I have an error about SwiftUI stage managment. I integrating a chat platform to my indie project. But it does not appear on the screen when new messages are sent. We can only see it after leaving the page and re-entering.</p>
  <p><strong>Page view init codes:</strong></p>
  <pre><code>@StateObject var chatVm : ChatViewModel
  @EnvironmentObject var auth: AuthService
  @State var message: String = &quot;&quot;
  let toUser: User?
  let fromUser : User?
  
  
  init(fromUser: User? , toUser: User?){
      self.toUser = toUser
      self.fromUser = fromUser
      _chatVm = StateObject&lt;ChatViewModel&gt;(wrappedValue: ChatViewModel(fromUser: fromUser!, toUser: toUser!))
  }
  </code></pre>
  <p><strong>View Model init codes</strong></p>
  <pre><code>@Published var messages: [Message] = [Message]()
  @Published var tmpMessages: [Message] = [Message]()
  
  @Published var lastMessageId: String = &quot;&quot;
  var toUser: User?
  var fromUser : User?
  var db = Firestore.firestore()
  
  
  init(fromUser: User, toUser: User){
          self.toUser = toUser
          self.fromUser = fromUser
          print(&quot;chat model okundu&quot;)
      DispatchQueue.main.async {
          self.getMessages()
      }
  }
  </code></pre>
  <p><strong>A part of getMessages()</strong></p>
  <pre><code>DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
              if let id = self.tmpMessages.last?.id {
                  self.lastMessageId = id
              }
              self.tmpMessages.sort { $0.timestamp &lt; $1.timestamp}
              self.messages = self.tmpMessages
          }
  </code></pre>