useCustomer
: Hook to access Customer data (theme, etc.)useHasMounted
: Hook to properly handle expected differences between server and browser rendering.useI18n
: Hook to access i18n/localisation datausePreviewMode
: Hook to access the native Next.js preview mode data/statususeUserSession
: Hook to access the user session dataHook to access customer data
The customer data are pre-fetched, either during SSR or SSG and are not meant to be fetched or modified by the app (they're kinda read-only)
Thus, it's fine to use React Context for this kind of usage.
1
2
3
const customer: Customer = useCustomer();
This hook helps rendering content only when the component has mounted (client-side).
It's helpful when you want some part of your app to only render on the client.
We strongly recommend reading The perils of rehydration to familiarise yourself with this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
const MyComponent: React.FunctionComponent<Props> = (props): JSX.Element => {
const hasMounted = useHasMounted();
if (!hasMounted) {
// Returns null on server-side
// Returns null on client-side, until the component has mounted
return null;
}
// Do stuff that will be executed only on the client-side, after rehydration
return (...)
};
export default MyComponent;
This hook helps access i18n data in any functional component.
1
2
3
const { lang, locale }: I18n = useI18n();
This hook helps access Next.js native Preview Mode data/status in any functional component.
1
2
3
const { preview }: PreviewMode = usePreviewMode();
This hook helps access user data in any functional component.
1
2
3
const { deviceId }: UserSession = useUserSession();
Custom Testing - 2021
Tous droits réservés