Question: I'm practicing react and fetch api and I want to send some data but it does not work... Code:

```
fetch('http://localhost:3003/users', {
        method: 'POST',
        body: JSON.stringify({ name, password }),
        headers: {
          'Content-Type': 'application/json'
        }
      })
        .then(res => {
          if (res.ok) {
            return res.json();
          }
          throw new Error('Error');
        })
        .then(user => {
          setUser([...users, user]);
          console.log(user.id);
          setLoggedUserID(user.id);
        })
        .then(setLoggedUserID(13)) // Check added user's ID
        .then(errorUserChange(false)); // Change state and go to /loggedin page

```

In second then I receive user with name, password and id. When I console.log it, I can see proper id, but when I'm trying to send it with setLoggedUserID function to the state, I receive null. This function works fine in the next then (third), but over there I don't have access to data (above I've hardcoded 13). Whole fetch is in function called after form submission. 

Any ideas? Thanks!

Answer: 
Here is possible approach

```
.navigationBarItems(trailing: self.tabIndex == 1 ? 
    AnyView(self.trailingButton) : AnyView(EmptyView()))

```

somewhere below `body`

```
var trailingButton: some View {
  Button(action: {print("Button was tapped")}) {
   Image(systemName: "plus")
    .resizable().frame(width: 20, height: 20)
  }
}

```
I know this question has an accepted answer and I used it in my own solution but here's what I did:

```
var doneButton:AnyView {
    if !fromPreferences {
        return AnyView(Button(action: self.doneAction) {
            Text("Done")
        })
    }
    return AnyView(EmptyView())
}

```

and how I used it in the body:

```
.navigationBarItems(trailing: doneButton)

```

thanks @Asperi for the solution!