0

The below line is used to GET data from the api, if there is is not any result it will return [] until it has some elements.

const { data, isLoading } =  useGetDataByRangeQuery(undefined, {
      selectFromResult: result => ({...result,data: {resp:(result.data === undefined ? [] : result.data),res:result} })
    })

Now, i need to pass some data to the useGetDataByRangeQuery as it is converted from get to post method.

let post_data = {"start":"yyyy-mm-dd","name":"some_name"}

const { data, isLoading } =  useGetDataByRangeQuery(post_data,undefined, {
      selectFromResult: result => ({...result,data: {resp:(result.data === undefined ? [] : result.data),res:result} })
    })

//In query page

export const dashboardData = createApi({
  reducerPath: 'petData',
  baseQuery: fetchBaseQuery({
    baseUrl: `${PetStoreApiEndpoint}/`,
    prepareHeaders: (headers) => {
        headers.set('Content-Type', 'application/json')
        headers.set('Accept', 'application/json')
        return headers
      },
  }),
  endpoints: (builder) => ({
    getDataByRange: builder.query({ 
      query: (arg) => ({url:'pet_data', method:'POST', body: arg}),
      transformResponse: (response) => {     
        return response.Items;
      }})
  }),

milas86534
  • 39
  • 4
  • Your call up there should be `useGetDataByRangeQuery(post_data, {` (without the undefined, there is exactly one argument to `query` and one options parameter), but generally I'm sorry I really don't understand the question. What do you want to do and what is your problem? – phry Apr 05 '22 at 08:16

0 Answers0