Skip to main content
Version: 4.xx.xx

Inferencer

You can automatically generate views for your resources using @refinedev/inferencer. Inferencer exports AntdListInferencer, AntdShowInferencer, AntdEditInferencer, AntdCreateInferencer and AntdInferencer (which combines all in one place) components.

Usage

Inferencer components can be imported from @refinedev/inferencer/antd. You can directly use the components in your routes without passing any props. If you use a routerProvider, it will infer the resource, action and id from the current route.

import routerProvider from "@refinedev/react-router-v6";
import { BrowserRouter } from "react-router-dom";
import { AntdInferencer } from "@refinedev/inferencer/antd";

const App = () => {
return (
<BrowserRouter>
<Refine
routerProvider={routerProvider}
resources={[
{
name: "samples",
list: "/samples",
},
]}
>
<Routes>
<Route path="/samples" element={<AntdInferencer />} />
</Routes>
</Refine>
</BrowserRouter>
);
};
info

To learn more about @refinedev/inferencer package, please check out Docs

Views

List

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

http://localhost:3000
import { Refine } from "@refinedev/core";
import { ThemedLayout, RefineThemes } from "@refinedev/antd";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";

import { ConfigProvider } from "antd";

import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";

import { AntdInferencer } from "@refinedev/inferencer/antd";

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

const App: React.FC = () => {
return (
<BrowserRouter>
<ConfigProvider theme={RefineThemes.Blue}>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
resources={[
{
name: "samples",
list: "/samples",
},
]}
>
<Routes>
<Route
element={
<ThemedLayout>
<Outlet />
</ThemedLayout>
}
>
<Route
path="/samples"
element={<AntdInferencer />}
/>
</Route>
</Routes>
</Refine>
</ConfigProvider>
</BrowserRouter>
);
};

Show

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

http://localhost:3000
import { Refine } from "@refinedev/core";
import { RefineThemes, ThemedLayout } from "@refinedev/antd";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";

import { ConfigProvider } from "antd";

import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";

import { AntdInferencer } from "@refinedev/inferencer/antd";

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

const App: React.FC = () => {
return (
<BrowserRouter>
<ConfigProvider theme={RefineThemes.Blue}>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
resources={[
{
name: "samples",
show: "/samples/show/:id",
},
]}
>
<Routes>
<Route
element={
<ThemedLayout>
<Outlet />
</ThemedLayout>
}
>
<Route
path="/samples/show/:id"
element={<AntdInferencer />}
/>
</Route>
</Routes>
</Refine>
</ConfigProvider>
</BrowserRouter>
);
};

Create

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 @refinedev/antd.

http://localhost:3000
import { Refine } from "@refinedev/core";
import { ThemedLayout, RefineThemes } from "@refinedev/antd";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";

import { ConfigProvider } from "antd";

import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";

import { AntdInferencer } from "@refinedev/inferencer/antd";

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

const App: React.FC = () => {
return (
<BrowserRouter>
<ConfigProvider theme={RefineThemes.Blue}>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
resources={[
{
name: "samples",
create: "/samples/create",
},
]}
>
<Routes>
<Route
element={
<ThemedLayout>
<Outlet />
</ThemedLayout>
}
>
<Route
path="/samples/create"
element={<AntdInferencer />}
/>
</Route>
</Routes>
</Refine>
</ConfigProvider>
</BrowserRouter>
);
};

Edit

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

http://localhost:3000
import { Refine } from "@refinedev/core";
import { ThemedLayout, RefineThemes } from "@refinedev/antd";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";

import { ConfigProvider } from "antd";

import { BrowserRouter, Routes, Route, Outlet } from "react-router-dom";

import { AntdInferencer } from "@refinedev/inferencer/antd";

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

const App: React.FC = () => {
return (
<BrowserRouter>
<ConfigProvider theme={RefineThemes.Blue}>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
resources={[
{
name: "samples",
edit: "/samples/edit/:id",
},
]}
>
<Routes>
<Route
element={
<ThemedLayout>
<Outlet />
</ThemedLayout>
}
>
<Route
path="/samples/edit/:id"
element={<AntdInferencer />}
/>
</Route>
</Routes>
</Refine>
</ConfigProvider>
</BrowserRouter>
);
};

Example

Below you'll find a Live CodeSandbox Example displaying a fully setup Refine app with @refinedev/inferencer/antd components.

RUN IN YOUR LOCAL
npm create refine-app@latest -- --example inferencer-antd