Search code examples
reactjsreduxreact-hooksreact-reduxredux-saga

Redux-saga pass query and options for POST body


I am trying to filter the data before displaying it in the React app

Of course, the data arrives well and is displayed correctly, but I am trying to filter it through a field in the database

When I try on Postman via Query everything is done correctly

I will attach a picture of Postman

My question in particular is the following How do I pass a query or options in saga knowing that it will be sent in the body

enter image description here

I have tried some solutions, but they are not working for you, as in the attached code

this saga

function* getServicesSupport() {
    try {
        const response  = yield call(getServicesSupportApi, {query: {categoryTickets : 2}, options: {limit: 3}});
        yield put(ServicesSupportApiResponseSuccess(GET_SERVICES_SUPPORT_LIST, response.data));
    } catch (error) {
        yield put(ServicesSupportApiResponseError(GET_SERVICES_SUPPORT_LIST, error));
    }
}

this getServicesSupportApi

  export const getServicesSupportList = () => api.post(url.GET_SERVICES_SUPPORT_LIST);

as you have seen in the picture for Postman,

a query was passed as my request is of type post

I'm new to react saga I don't know how to pass a query or options

I know very well how to pass a parameter in the request,

but I do not know how to pass a query

I need to pass more than one query in other requests, filters and sort or populate ....

So it is very important for me to know how to pass query as in


Solution

  • Assuming your api.get supports sending the body/query params, e.g. like api.get(url.GET_SERVICES_SUPPORT_LIST, {categoryTickets: 2}) you can modify the call effect to pass down the values

    const getServicesSupportList = (payload) => api.post(url.GET_SERVICES_SUPPORT_LIST, payload);
    let response = yield call(getServicesSupportApi, {categoryTickets : 2});