Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

268
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda