Is it okay to set presentation in a useEffect with setOptions, or would it hurt performance?
#4067
Replies: 1 comment 1 reply
-
|
Hey! I'm surprised that it's the first time somebody asks and that we haven't documented that in the native stack docs in react-navigation, however setting presentation in useEffect does not make sense and is not supported. The intended presentation for the screen MUST be known at first-render time. Imagine that after first render, on native side I receive a new screen with Hence, it is not supported and likely won't be. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Consider a screen like this:
This pattern is good for DX because it keeps implementation details of the screen inside that screen's component. This code also works on both Android and iOS — the screen is presented as a bottom sheet from the start.
However, considering that
useEffectruns asynchronously after the screen has already rendered with default options, would this hurt performance? Is it possible that on slower devices there would be a noticeable UI shift or a frame drop due to this? Would this mess with accessibility announcements?I know that
useLayoutEffectis also an option, but unfortunately it only works withsetOptionson Android, but not on iOS.Thanks!
Beta Was this translation helpful? Give feedback.
All reactions