Skip to main content
Version: 4.xx.xx

Inferencer

You can automatically generate views for your resources using @refinedev/inferencer. Inferencer exports MuiListInferencer, MuiShowInferencer, MuiEditInferencer, MuiCreateInferencer and MuiInferencer (which combines all in one place) components.

Usage​

Inferencer components can be imported from @refinedev/inferencer/mui. 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 { LightTheme } from "@refinedev/mui";
import { CssBaseline, GlobalStyles, ThemeProvider } from "@mui/material";

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

import { MuiInferencer } from "@refinedev/inferencer/mui";

const App = () => {
return (
<ThemeProvider theme={LightTheme}>
<CssBaseline />
<GlobalStyles styles={{ html: { WebkitFontSmoothing: "auto" } }} />
<BrowserRouter>
<Refine
routerProvider={routerProvider}
resources={[
{
name: "samples",
list: "/samples",
},
]}
>
<Routes>
<Route path="/samples" element={<MuiInferencer />} />
</Routes>
</Refine>
</BrowserRouter>
</ThemeProvider>
);
};
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 component and useDatagrid hook from @refinedev/mui.

http://localhost:3000/posts
import { Refine } from "@refinedev/core";
import { Layout, LightTheme } from "@refinedev/mui";
import { CssBaseline, GlobalStyles, ThemeProvider } from "@mui/material";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";

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

import { MuiInferencer } from "@refinedev/inferencer/mui";

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

const App: React.FC = () => {
return (
<ThemeProvider theme={LightTheme}>
<CssBaseline />
<GlobalStyles styles={{ html: { WebkitFontSmoothing: "auto" } }} />
<BrowserRouter>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
resources={[
{
name: "samples",
list: "/samples",
}
]}
>
<Routes>
<Route
element={(
<Layout>
<Outlet />
</Layout>
)}
>
<Route path="/samples" element={<MuiInferencer />} />
</Route>
</Routes>
</Refine>
</BrowserRouter>
</ThemeProvider>
);
};

Show​

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

http://localhost:3000/samples/show/123
import { Refine } from "@refinedev/core";
import { Layout, LightTheme } from "@refinedev/mui";
import { CssBaseline, GlobalStyles, ThemeProvider } from "@mui/material";

import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";

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

import { MuiInferencer } from "@refinedev/inferencer/mui";

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

const App: React.FC = () => {
return (
<ThemeProvider theme={LightTheme}>
<CssBaseline />
<GlobalStyles styles={{ html: { WebkitFontSmoothing: "auto" } }} />
<BrowserRouter>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
resources={[
{
name: "samples",
show: "/samples/show/:id",
}
]}
>
<Routes>
<Route
element={(
<Layout>
<Outlet />
</Layout>
)}
>
<Route path="/samples/show/:id" element={<MuiInferencer />} />
</Route>
</Routes>
</Refine>
</BrowserRouter>
</ThemeProvider>
);
};

Create​

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

http://localhost:3000/samples/create
import { Refine } from "@refinedev/core";
import { Layout, LightTheme } from "@refinedev/mui";
import { CssBaseline, GlobalStyles, ThemeProvider } from "@mui/material";

import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";

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

import { MuiInferencer } from "@refinedev/inferencer/mui";

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

const App: React.FC = () => {
return (
<ThemeProvider theme={LightTheme}>
<CssBaseline />
<GlobalStyles styles={{ html: { WebkitFontSmoothing: "auto" } }} />
<BrowserRouter>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
resources={[
{
name: "samples",
create: "/samples/create",
}
]}
>
<Routes>
<Route
element={(
<Layout>
<Outlet />
</Layout>
)}
>
<Route path="/samples/create" element={<MuiInferencer />} />
</Route>
</Routes>
</Refine>
</BrowserRouter>
</ThemeProvider>
);
};

Edit​

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

http://localhost:3000/samples/edit/123
import { Refine } from "@refinedev/core";
import { Layout, LightTheme } from "@refinedev/mui";
import { CssBaseline, GlobalStyles, ThemeProvider } from "@mui/material";

import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";

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

import { MuiInferencer } from "@refinedev/inferencer/mui";

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

const App: React.FC = () => {
return (
<ThemeProvider theme={LightTheme}>
<CssBaseline />
<GlobalStyles styles={{ html: { WebkitFontSmoothing: "auto" } }} />
<BrowserRouter>
<Refine
routerProvider={routerProvider}
dataProvider={dataProvider(API_URL)}
resources={[
{
name: "samples",
edit: "/samples/edit/:id",
}
]}
>
<Routes>
<Route
element={(
<Layout>
<Outlet />
</Layout>
)}
>
<Route path="/samples/edit/:id" element={<MuiInferencer />} />
</Route>
</Routes>
</Refine>
</BrowserRouter>
</ThemeProvider>
);
};

Example​

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

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