Skip to main content
Version: 3.xx.xx

Inferencer

You can automatically generate views for your resources using @pankod/refine-inferencer. Inferencer exports AntdListInferencer, AntdShowInferencer, AntdCreateInferencer and AntdEditInferencer components.

Usage

Ant Design components can be imported from @pankod/refine-inferencer/antd. You can directly use the components in resources prop of Refine component or you can use them in your custom components by passing the resource prop as the resource name.

import {
AntdListInferencer,
AntdShowInferencer,
AntdCreateInferencer,
AntdEditInferencer,
} from "@pankod/refine-inferencer/antd";

const App = () => {
return (
<Refine
resources={[
{
name: "samples",
list: AntdListInferencer,
show: AntdShowInferencer,
create: AntdCreateInferencer,
edit: AntdEditInferencer,
},
]}
/>
);
};
info

To learn more about @pankod/refine-inferencer package, please check out Docs

Views

AntdListInferencer

Generates a sample list view for your resources according to the API response. It uses List and Table components with useTable hook from @pankod/refine-antd.

http://localhost:3000/samples
import { Refine } from "@pankod/refine-core";
import { Layout } from "@pankod/refine-antd";
import routerProvider from "@pankod/refine-react-router-v6";
import dataProvider from "@pankod/refine-simple-rest";

import {
AntdListInferencer,
AntdShowInferencer,
AntdCreateInferencer,
AntdEditInferencer,
} from "@pankod/refine-inferencer/antd";

const API_URL = "https://api.fake-rest.refine.dev";

const App: React.FC = () => {
return (
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
Layout={Layout}
resources={[
{
name: "samples",
list: AntdListInferencer,
show: AntdShowInferencer,
create: AntdCreateInferencer,
edit: AntdEditInferencer,
canDelete: true,
},
{
name: "categories",
list: AntdListInferencer,
show: AntdShowInferencer,
},
{
name: "tags",
list: AntdListInferencer,
show: AntdShowInferencer,
},
]}
/>
);
};

AntdShowInferencer

Generates a sample show view for your resources according to the API response. It uses Show and field components from @pankod/refine-antd with useShow hook from @pankod/refine-core.

http://localhost:3000/samples/show/123
import { Refine } from "@pankod/refine-core";
import { Layout } from "@pankod/refine-antd";
import routerProvider from "@pankod/refine-react-router-v6";
import dataProvider from "@pankod/refine-simple-rest";

import {
AntdListInferencer,
AntdShowInferencer,
AntdCreateInferencer,
AntdEditInferencer,
} from "@pankod/refine-inferencer/antd";

const API_URL = "https://api.fake-rest.refine.dev";

const App: React.FC = () => {
return (
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
Layout={Layout}
resources={[
{
name: "samples",
list: AntdListInferencer,
show: AntdShowInferencer,
create: AntdCreateInferencer,
edit: AntdEditInferencer,
canDelete: true,
},
{
name: "categories",
list: AntdListInferencer,
show: AntdShowInferencer,
},
{
name: "tags",
list: AntdListInferencer,
show: AntdShowInferencer,
},
]}
/>
);
};

AntdCreateInferencer

Generates a sample create view for your resources according to the first record in list API response. It uses Create component and useForm hook from @pankod/refine-antd.

http://localhost:3000/samples/create
import { Refine } from "@pankod/refine-core";
import { Layout } from "@pankod/refine-antd";
import routerProvider from "@pankod/refine-react-router-v6";
import dataProvider from "@pankod/refine-simple-rest";

import {
AntdListInferencer,
AntdShowInferencer,
AntdCreateInferencer,
AntdEditInferencer,
} from "@pankod/refine-inferencer/antd";

const API_URL = "https://api.fake-rest.refine.dev";

const App: React.FC = () => {
return (
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
Layout={Layout}
resources={[
{
name: "samples",
list: AntdListInferencer,
show: AntdShowInferencer,
create: AntdCreateInferencer,
edit: AntdEditInferencer,
canDelete: true,
},
{
name: "categories",
list: AntdListInferencer,
show: AntdShowInferencer,
},
{
name: "tags",
list: AntdListInferencer,
show: AntdShowInferencer,
},
]}
/>
);
};

AntdEditInferencer

Generates a sample edit view for your resources according to the API response. It uses Edit component and useForm hook from @pankod/refine-antd.

http://localhost:3000/samples/edit/123
import { Refine } from "@pankod/refine-core";
import { Layout } from "@pankod/refine-antd";
import routerProvider from "@pankod/refine-react-router-v6";
import dataProvider from "@pankod/refine-simple-rest";

import {
AntdListInferencer,
AntdShowInferencer,
AntdCreateInferencer,
AntdEditInferencer,
} from "@pankod/refine-inferencer/antd";

const API_URL = "https://api.fake-rest.refine.dev";

const App: React.FC = () => {
return (
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
Layout={Layout}
resources={[
{
name: "samples",
list: AntdListInferencer,
show: AntdShowInferencer,
create: AntdCreateInferencer,
edit: AntdEditInferencer,
canDelete: true,
},
{
name: "categories",
list: AntdListInferencer,
show: AntdShowInferencer,
},
{
name: "tags",
list: AntdListInferencer,
show: AntdShowInferencer,
},
]}
/>
);
};

Live StackBlitz Example

Below you'll find a Live StackBlitz Example displaying a fully setup Refine app with @pankod/refine-inferencer/antd components.