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: 
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!
Here is what worked for me, even when my condition was false which resulted in nothing being returned (the bar item correctly did not show, without errors). I find it a little cleaner than squeezing in a ternary operator.

```
.navigationBarItems(
    trailing: Button(
        action: {
            print("My Action")
        }
    ) {
        if myBool {
            Text("My Button")
        }
    }
)

```