specific-silverS
Refine3y ago
8 replies
specific-silver

useCustom transform response.

I have an array of vehicle models fetched from api. The sample model as follows

[
                {
                    "id": 95,
                    "name": "Nexon",
                    "transmission": [
                        "automatic",
                        "manual"
                    ],
                    "fuel_types": [
                        "petrol",
                        "diesel",
                        "electric",
                        "hybrid"
                    ],
                    "vehicle_type": "suv"
                }
]


My data model looks like this:
interface IVehicleModel {
  id: number;
  name: string;
  transmission: string[];
  fuelTypes: string[];
  vehicleType: string;
  make?: string;
}

How to map vehicle_type and fuel_types to vehicleType and fuelType of data model.

const { data, isLoading } = useCustom<VehicleResponse>({
    url: `${API_URL}/api/v1/vehicles`,
    method: "get",
    config: {
      query: {
        offset: currentPage - 1,
        limit: limit,
      },
    },
  });
Was this page helpful?