Docs: Add contributor docs for the userEnterprise hook

This commit is contained in:
Gustav Hansen 2023-06-13 06:28:00 +02:00
parent 9d554ec9aa
commit 721318eed1

View File

@ -0,0 +1,56 @@
---
title: useEnterprise
description: API reference for the useEnterprise hook
tags:
- admin
- hooks
- users
---
A hook that returns either community or enterprise-edition data-structures based on the global `window.strapi.isEE` flag.
## Usage
```
import { CE_DATA } from './data';
function Component() {
const data = useEnterprise(CE_DATA, async () => (await import('./ee/data')).default);
}
```
It accepts an optional third argument to pass in options customizing the hook behavior:
### `combine()`
THe `combine` callback can be used as a custom "merge" function for the ce and ee arguments:
```
const data = useEnterprise({ a: 1 }, () => { b: 1 }, { combine(ce, ee) { return { ...ce, ...ee } } });
console.log(data); // { a: 1, b: 1 }
```
### `defaultValue`
By default the hook returns `null` if `window.strapi.isEE` is true and the enterprise data structure is not yet loaded. Customizing
this value can help implementing various loading scenarios:
```
// display a loading state while an EE component is loading
const Component = useEnterprise(() => <p>CE</p>, () => <p>EE</p>, {
defaultValue: () => <div>loading ...</div>
})
// display nothing while an EE component is loading, but don't block the overall rendering
const Component = useEnterprise(() => <p>CE</p>, () => <p>EE</p>, {
defaultValue: () => null
})
// display nothing while an EE component is loading
const Component = useEnterprise(() => <p>CE</p>, () => <p>EE</p>)
if (!Component) {
return;
}
```