Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

267
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda