Files
rn-app/hooks/useClientOnlyValue.ts

23 lines
736 B
TypeScript
Raw Normal View History

2025-11-06 16:37:01 +08:00
/**
* Client-only value Hook
2025-11-13 16:47:10 +08:00
*
2025-11-06 16:37:01 +08:00
* This hook is used to provide different values for server-side rendering (SSR)
* and client-side rendering. It's particularly useful for React Native Web
* to prevent hydration errors.
2025-11-13 16:47:10 +08:00
*
2025-11-06 16:37:01 +08:00
* @param server - Value to use during server-side rendering
* @param client - Value to use during client-side rendering
* @returns The appropriate value based on the rendering context
2025-11-13 16:47:10 +08:00
*
2025-11-06 16:37:01 +08:00
* @example
* ```tsx
* // Disable header on server, enable on client
* headerShown: useClientOnlyValue(false, true)
* ```
*/
// This function is web-only as native doesn't currently support server (or build-time) rendering.
export function useClientOnlyValue<S, C>(server: S, client: C): S | C {
return client;
}