tachybase_todo/docs/en-US/development/client/index.md

73 lines
1.6 KiB
Markdown
Raw Normal View History

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