mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 15:13:21 +00:00
Docs: Add contributor docs for the userEnterprise hook
This commit is contained in:
parent
9d554ec9aa
commit
721318eed1
56
docs/docs/docs/01-core/admin/04-hooks/use-enterprise.mdx
Normal file
56
docs/docs/docs/01-core/admin/04-hooks/use-enterprise.mdx
Normal 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;
|
||||
}
|
||||
```
|
||||
Loading…
x
Reference in New Issue
Block a user