2022-11-08 03:15:21 +00:00
|
|
|
# Overview
|
2022-10-31 14:41:24 +00:00
|
|
|
|
2022-11-08 03:15:21 +00:00
|
|
|
Most of the extensions for the NocoBase client are provided as Providers.
|
2022-10-31 14:41:24 +00:00
|
|
|
|
2022-11-08 03:15:21 +00:00
|
|
|
## Built-in Providers
|
2022-10-31 14:41:24 +00:00
|
|
|
|
|
|
|
- APIClientProvider
|
|
|
|
- I18nextProvider
|
|
|
|
- AntdConfigProvider
|
|
|
|
- RemoteRouteSwitchProvider
|
|
|
|
- SystemSettingsProvider
|
|
|
|
- PluginManagerProvider
|
|
|
|
- SchemaComponentProvider
|
|
|
|
- SchemaInitializerProvider
|
|
|
|
- BlockSchemaComponentProvider
|
|
|
|
- AntdSchemaComponentProvider
|
|
|
|
- DocumentTitleProvider
|
|
|
|
- ACLProvider
|
|
|
|
|
2022-11-08 03:15:21 +00:00
|
|
|
## Registration of client-side Provider modules
|
2022-10-31 14:41:24 +00:00
|
|
|
|
2022-11-08 03:15:21 +00:00
|
|
|
Static Providers are registered with app.use() and dynamic Providers are adapted with dynamicImport.
|
2022-10-31 14:41:24 +00:00
|
|
|
|
|
|
|
```tsx | pure
|
|
|
|
import React from 'react';
|
|
|
|
import { Application } from '@nocobase/client';
|
|
|
|
|
|
|
|
const app = new Application({
|
|
|
|
apiClient: {
|
|
|
|
baseURL: process.env.API_BASE_URL,
|
|
|
|
},
|
|
|
|
dynamicImport: (name: string) => {
|
2022-11-08 03:15:21 +00:00
|
|
|
return import(`... /plugins/${name}`);
|
2022-10-31 14:41:24 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-11-08 03:15:21 +00:00
|
|
|
// When visiting the /hello page, display Hello world!
|
2022-10-31 14:41:24 +00:00
|
|
|
const HelloProvider = React.memo((props) => {
|
|
|
|
const location = useLocation();
|
|
|
|
if (location.pathname === '/hello') {
|
|
|
|
return <div>Hello world!</div>
|
|
|
|
}
|
|
|
|
return <>{props.children}</>
|
|
|
|
});
|
2023-06-06 11:33:04 +00:00
|
|
|
HelloProvider.displayName = 'HelloProvider'
|
2022-10-31 14:41:24 +00:00
|
|
|
|
|
|
|
app.use(HelloProvider);
|
|
|
|
```
|
|
|
|
|
2022-11-08 03:15:21 +00:00
|
|
|
## Client-side of plugins
|
2022-10-31 14:41:24 +00:00
|
|
|
|
2022-11-08 03:15:21 +00:00
|
|
|
Directory structure of the client-side of an empty plugin is as follows
|
2022-10-31 14:41:24 +00:00
|
|
|
|
|
|
|
```bash
|
|
|
|
|- /my-plugin
|
|
|
|
|- /src
|
|
|
|
|- /client
|
|
|
|
|- index.tsx
|
|
|
|
|- client.d.ts
|
|
|
|
|- client.js
|
|
|
|
```
|
|
|
|
|
2022-11-08 03:15:21 +00:00
|
|
|
``client/index.tsx`` reads as follows.
|
2022-10-31 14:41:24 +00:00
|
|
|
|
|
|
|
```tsx | pure
|
|
|
|
import React from 'react';
|
|
|
|
|
2022-11-08 03:15:21 +00:00
|
|
|
// This is an empty Provider, only children are passed, no custom Context is provided
|
2022-10-31 14:41:24 +00:00
|
|
|
export default React.memo((props) => {
|
|
|
|
return <>{props.children}</>;
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2022-11-08 03:15:21 +00:00
|
|
|
After the plugin pm.add, it writes the `my-plugin.ts` file to the `packages/app/client/src/plugins` directory.
|