tamagui: useMedia hook having wrong initial value in some situations
Current Behavior
- Using the useMedia hook in a
_layout.tsxfile - Having a conditional return above the access of the proxy e.g.
media.sm - In some cases (I was not able to reproduce it yet with the starter template) this leads to the hook not updating correctly after refresh
- In the provided example code
isLoadingis initialized with true and after some time changes to false. - When
media.smis accessed before the conditional return it updates correctly e.g. addingconsole.log(media.sm)directly after the hook (which I guess defeats the purpose of static optimizations)
Expected Behavior
No response
Tamagui Version
1.101.7
Platform (Web, iOS, Android)
Web
Reproduction
const {session, isLoading, signOut} = useSession();
const media = useMedia();
if (isLoading) {
return <Text>Loading...</Text>; // This early return leads to useMedia not updating
}
console.log('media.sm in _layout.tsx', media.sm);
return <Slot />
What fixes it:
const {session, isLoading, signOut} = useSession();
const media = useMedia();
console.log('media.sm in _layout.tsx', media.sm);
if (isLoading) {
return <Text>Loading...</Text>; // This early return leads to useMedia not updating
}
return <Slot />
### System Info
_No response_
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 5
- Comments: 15 (5 by maintainers)
Yeah but it is causing other issues on other components with hydration. We need a proper way to handle it @natew