Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

ReactNative queryString not formatting correctly

$
0
0

I am trying to fetch data based on a query. However, if i pass a query to my api call and format the queryString. The result will look like this:

Object {"DE": null,"limit": 10,"offset": 0,}

When fomratted correctly, the Object should look like this:

Object {"query": "DE","limit": 10,"offset": 0,}

(For showcasing my issue I set a default value fro my query). My API call looks like this:

export function thunkFetchOrders(    query = 'DE',    offset = 0,    limit = 10,    filters = {}) {    return async (dispatch: any) => {        if (offset === 0) {            dispatch(                resetOrders()            )        }        let requestParams = {            offset,            limit,        }        requestParams = {...requestParams, ...setFilter(filters)}        if (query) {            requestParams = {...requestParams, ...queryString.parse(query)}        }        try {            const res = await axios.get(`/orders`, {params: requestParams})            await dispatch(                fetchOrders(                    res.data,                    limit,                    offset,                    filters                )            )            }        catch (error) {            await dispatch(thunkFetchError(error));        }    }}

What am I doing wrong here?


Viewing all articles
Browse latest Browse all 6287

Trending Articles