Ways to bootstrap the state?

There are times where I have to bootstrap the state of a view. I usually do the onAppear with custom guards when, say, said view could be covered by child sheet (where dismissing the sheet would trigger onAppear again).

Another one that I have considered, but not yet tried is to use a if !viewState.isBooted in a View and present a view that accepts a callback that is called in that view's onAppear, change the isBooted in the reducer and then not show that view anymore.

I wonder if there is another way to bootstrap a state without using onAppear view's modifier.

There are a lot of options here, but we like modeling this kind of thing as optional state that is managed/initialized by the parent domain. So rather than using onAppear on the child to initialize the child, we hook into the parent action intent of navigating to that screen to set the child to some non-nil state. The benefit of this is optionality can drive the navigation itself, though it comes with some caveats around the child feature's lifecycle, like tearing down effects, etc.

We've been exploring navigation patterns a lot this year and hope to make improvements soon!


Thanks for the reply! I wonder how does making an optional child state ties into triggering an event when the state gets created?

Terms of Service

Privacy Policy

Cookie Policy