Skip to main content
Version: 4.xx.xx

Inferencer

You can automatically generate views for your resources using @refinedev/inferencer. Inferencer exports ChakraUIListInferencer, ChakraUIShowInferencer, ChakraUIEditInferencer, ChakraUICreateInferencer components and finally the ChakraUIInferencer component, which combines all in one place.

Usage

Inferencer components can be imported from @refinedev/inferencer/chakra-ui. 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 { Layout, refineTheme } from "@refinedev/chakra-ui";
import { ChakraProvider } from "@chakra-ui/react";

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

import { ChakraUIInferencer } from "@refinedev/inferencer/chakra-ui";

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

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

Views

List

Generates a sample list view for your resources according to the API response. It uses the List component from @refinedev/chakra-ui and useTable hook from @refinedev/react-table.

localhost:3000/samples
import { Refine } from "@refinedev/core";
import { ThemedLayoutV2, RefineThemes } from "@refinedev/chakra-ui";
import { ChakraProvider } from "@chakra-ui/react";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";

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

import { ChakraUIInferencer } from "@refinedev/inferencer/chakra-ui";

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

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

Show

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

localhost:3000/samples/show/123
import { Refine } from "@refinedev/core";
import { ThemedLayoutV2, RefineThemes } from "@refinedev/chakra-ui";
import { ChakraProvider } from "@chakra-ui/react";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";

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

import { ChakraUIInferencer } from "@refinedev/inferencer/chakra-ui";

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

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

Create

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

localhost:3000/samples/create
import { Refine } from "@refinedev/core";
import { ThemedLayoutV2, RefineThemes } from "@refinedev/chakra-ui";
import { ChakraProvider } from "@chakra-ui/react";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";

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

import { ChakraUIInferencer } from "@refinedev/inferencer/chakra-ui";

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

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

Edit

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

localhost:3000/samples/edit/123
import { Refine } from "@refinedev/core";
import { ThemedLayoutV2, RefineThemes } from "@refinedev/chakra-ui";
import { ChakraProvider } from "@chakra-ui/react";
import routerProvider from "@refinedev/react-router-v6";
import dataProvider from "@refinedev/simple-rest";

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

import { ChakraUIInferencer } from "@refinedev/inferencer/chakra-ui";

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

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

Example

Below, you will find a Live CodeSandbox Example displaying a fully setup Refine app with the @refinedev/inferencer/chakra-ui components.

Run on your local
npm create refine-app@latest -- --example inferencer-chakra-ui