Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

266
Views
How to custom identifiers/primary keys for my resources in react-admin

I have a nextJS project that use redux for state management and react admin for admin panel. I took my keys not as id instead _id. So I followed this custom identifiers.

My App.js

// in src/App.js
import * as React from "react";
import { Provider } from "react-redux";
import { createHashHistory } from "history";
import { Admin, Resource, ListGuesser, fetchUtils } from "react-admin";
import jsonServerProvider from "ra-data-json-server";
import createAdminStore from "./createAdminStore";
import convertHTTPResponseToREST from "./dataProvider";

// dependency injection
const dataProvider = jsonServerProvider(
  convertHTTPResponseToREST("http://localhost:3000/api/products")
);
const authProvider = () => Promise.resolve();

const history = createHashHistory();

const App = () => (
  <Provider
    store={createAdminStore({
      authProvider,
      dataProvider,
      history,
    })}
  >
    <Admin title="Dashboard" dataProvider={dataProvider} history={history}>
      <Resource name="products" list={ListGuesser} />
    </Admin>
  </Provider>
);

export default App;


my dataProvider.js

import {
  CREATE,
  DELETE,
  GET_LIST,
  GET_MANY_REFERENCE,
  GET_ONE,
  UPDATE,
} from "react-admin";

const convertHTTPResponseToREST = (response, type, resource, params) => {
  const { headers, json } = response;
  switch (type) {
    case GET_LIST:
      return {
        data: json.map((resource) => ({ ...resource, id: resource._id })),
        total: parseInt(headers.get("content-range").split("/").pop(), 10),
      };
    case UPDATE:
    case DELETE:
    case GET_ONE:
      return { ...json, id: json._id };
    case CREATE:
      return { ...params.data, id: json._id };
    default:
      return json;
  }
};

export default convertHTTPResponseToREST;

So how to use convertHTTPResponseToRest function inside the Admin tag?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are seeing the documentation of admin-on-rest.

This is the documentation of react-admin:

https://marmelab.com/react-admin/FAQ.html#can-i-have-custom-identifiersprimary-keys-for-my-resources

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!