2021-10-28 22:55:51 +08:00
---
order: 2
---
# Client-side Kernel
2021-10-31 09:44:52 +08:00
To allow more non-developers to participate, NocoBase provides a companion client-side plugin -- a visual configuration interface with no code. The core of this part is @nocobase/client , which ideally can be used within any front-end build tool or framework, e.g.
2021-10-28 22:55:51 +08:00
- umijs
- create-react-app
- icejs
- vite
- snowpack
- nextjs
2021-10-31 09:44:52 +08:00
- Other
2021-10-28 22:55:51 +08:00
2021-10-31 09:44:52 +08:00
For the time being only support umijs (packaging compilation is still some problems), the future will gradually support the above-listed frameworks.
2021-10-28 22:55:51 +08:00
2021-10-31 09:44:52 +08:00
The main components of the client include.
2021-10-28 22:55:51 +08:00
2021-10-31 09:44:52 +08:00
## Request
2021-10-28 22:55:51 +08:00
- API Client
- Request Hook
```ts
const api = new APIClient({
2021-10-31 09:44:52 +08:00
request,
2021-10-28 22:55:51 +08:00
});
api.auth();
api.get();
api.post();
api.resource('collections').create();
api.resource('collections').findOne({});
api.resource('collections').findMany({});
2021-10-31 09:44:52 +08:00
api.resource('collections').relationship('fields').of(1).create();
2021-10-28 22:55:51 +08:00
```
2021-10-31 09:44:52 +08:00
The following details are TBD, special resources
2021-10-28 22:55:51 +08:00
```js
api.collections.create();
api.uiSchemas.create();
```
Request Hook
[https://www.npmjs.com/package/@ahooksjs/use-request ](https://www.npmjs.com/package/@ahooksjs/use-request )
```js
const { data } = useRequest(() => api.resource('users').findMany());
```
2021-10-31 09:44:52 +08:00
## Routing
2021-10-28 22:55:51 +08:00
- createRouteSwitch
```js
const RouteSwitch = createRouteSwitch({
2021-10-31 09:44:52 +08:00
components: {},
2021-10-28 22:55:51 +08:00
});
< RouteSwitch routes = {[]} / >
```
2021-10-31 09:44:52 +08:00
## Schema component
2021-10-28 22:55:51 +08:00
- createSchemaComponent
```js
function Hello() {
2021-10-31 09:44:52 +08:00
return < div > Hello Word< / div >
2021-10-28 22:55:51 +08:00
}
const SchemaComponent = createSchemaComponent({
scope,
components: {
2021-10-31 09:44:52 +08:00
Hello
2021-10-28 22:55:51 +08:00
},
});
const schema = {
type: 'void',
2021-10-31 09:44:52 +08:00
'x-component': 'Hello',
2021-10-28 22:55:51 +08:00
};
< SchemaComponent schema = {schema} / >
```
2021-10-31 09:44:52 +08:00
## How do you assemble it?
2021-10-28 22:55:51 +08:00
< pre lang = "tsx" >
import { I18nextProvider } from 'react-i18next';
import { createRouteSwitch, APIClient } from '@nocobase/client';
const apiClient = new APIClient();
const i18n = i18next.createInstance();
const Hello = () => {
2021-10-31 09:44:52 +08:00
return < div > Hello< / div > ;
2021-10-28 22:55:51 +08:00
}
const SchemaComponent = createSchemaComponent({
2021-10-31 09:44:52 +08:00
components: {
2021-10-28 22:55:51 +08:00
Hello,
},
});
const PageTemplate = () => {
const schema = {
2021-10-31 09:44:52 +08:00
type: 'void',
2021-10-28 22:55:51 +08:00
'x-component': 'Hello',
};
2021-10-31 09:44:52 +08:00
return (
< SchemaComponent schema = {schema}/ >
2021-10-28 22:55:51 +08:00
);
}
const RouteSwitch = createRouteSwitch({
2021-10-31 09:44:52 +08:00
components: {
2021-10-28 22:55:51 +08:00
PageTemplate,
},
});
const routes = [
{ path: '/hello', component: 'Hello' },
];
function AntdProvider(props) {
2021-10-31 09:44:52 +08:00
// The locale here can be handled dynamically depending on the i18next
return (
2021-10-31 11:35:11 +08:00
< ConfigProvider locale = {locale} > {props.children}< / ConfigProvider >
2021-10-28 22:55:51 +08:00
);
}
const App = () => {
2021-10-31 09:44:52 +08:00
return (
2021-10-28 22:55:51 +08:00
< APIClientProvider client = {apiClient} >
< I18nextProvider i18n = {i18n} >
2021-10-31 11:35:11 +08:00
< AntdProvider >
< Router >
< RouteSwitch routes = {routes}/ >
2021-10-28 22:55:51 +08:00
< / Router >
< / AntdProvider >
< / I18nextProvider >
< / APIClientProvider >
);
}
< / pre >
2021-10-31 09:44:52 +08:00
- APIClientProvider: provides the APIClient
- I18nextProvider: internationalization
- AntdProvider: handles the internationalization of antd components, which needs to be placed in I18nextProvider
- Router: route driver
- RouteSwitch: route distribution
2021-10-28 22:55:51 +08:00
2021-10-31 09:44:52 +08:00
The above code may seem a bit verbose, but the actual function and role of each part is not the same, so it is not suitable for over-encapsulation. If needed, it can be further encapsulated according to the actual situation.