polen
Version:
A framework for delightful GraphQL developer portals
16 lines • 573 B
JavaScript
import { useEffect, useState } from 'react';
/**
* Hook that returns a server value during SSR and switches to client value after hydration
*
* @param clientValue - Function that returns the value to use on the client
* @param serverValue - Value to use during SSR
* @returns The appropriate value based on rendering context
*/
export function useClientOnly(clientValue, serverValue) {
const [value, setValue] = useState(serverValue);
useEffect(() => {
setValue(clientValue());
}, []);
return value;
}
//# sourceMappingURL=useClientOnly.js.map