--- layout: default title: "The Resource Component" --- # The `` component A `` component maps one API endpoint to a CRUD interface. For instance, the following admin app offers a read-only interface to the resources exposed by the JSONPlaceholder API at [`http://jsonplaceholder.typicode.com/posts`](http://jsonplaceholder.typicode.com/posts) and [`http://jsonplaceholder.typicode.com/users`](http://jsonplaceholder.typicode.com/users): ```jsx // in src/App.js import React from 'react'; import { Admin, Resource } from 'react-admin'; import jsonServerProvider from 'ra-data-json-server'; import { PostList } from './posts'; import { UserList } from './users'; const App = () => ( ); ``` `` allows you to define a component for each CRUD operation, using the following prop names: * `list` (if defined, the resource is displayed on the Menu) * `create` * `edit` * `show` Here is a more complete admin, with components for all the CRUD operations: ```jsx import React from 'react'; import { Admin, Resource } from 'react-admin'; import jsonServerProvider from 'ra-data-json-server'; import { PostList, PostCreate, PostEdit, PostShow, PostIcon } from './posts'; import { UserList } from './posts'; import { CommentList, CommentEdit, CommentCreate, CommentIcon } from './comments'; const App = () => ( ); ``` **Tip**: Under the hood, the `` component uses react-router to create several routes: * `/` maps to the `list` component * `/create` maps to the `create` component * `/:id` maps to the `edit` component * `/:id/show` maps to the `show` component **Tip**: You must add a `` when you declare a reference (via ``, ``, ``, `` or ``), because react-admin uses resources to define the data store structure. That's why there is an empty `tag` resource in the example above. `` also accepts additional props: * [`name`](#name) * [`icon`](#icon) * [`options`](#icon) ## `name` React-admin uses the `name` prop both to determine the API endpoint (passed to the `dataProvider`), and to form the URL for the resource. ```jsx ``` For this resource react-admin will fetch the `http://jsonplaceholder.typicode.com/posts` endpoint for data. The routing will map the component as follows: * `/posts/` maps to `PostList` * `/posts/create` maps to `PostCreate` * `/posts/:id` maps to `PostEdit` * `/posts/:id/show` maps to `PostShow` **Tip**: If you want to use a special API endpoint (e.g. 'http://jsonplaceholder.typicode.com/my-custom-posts-endpoint') without altering the URL in the react-admin application (so still use `/posts`), write the mapping from the resource `name` (`posts`) to the API endpoint (`my-custom-posts-endpoint`) in your own [`dataProvider`](./Admin.md#dataprovider) ## `icon` React-admin will render the `icon` prop component in the menu: ```jsx // in src/App.js import React from 'react'; import PostIcon from '@material-ui/icons/Book'; import UserIcon from '@material-ui/icons/People'; import { Admin, Resource } from 'react-admin'; import jsonServerProvider from 'ra-data-json-server'; import { PostList } from './posts'; const App = () => ( ); ``` ## options `options.label` allows to customize the display name of a given resource in the menu. {% raw %} ```jsx ``` {% endraw %}