axios transformRequest - how to alter JSON payload

axios.create({
    transformRequest: [(data, headers) => {
        // modify data here
        return data;
    }, ...axios.defaults.transformRequest]
});

have to append the original axios.defaults.transformRequest to the transformRequest option here..


Wouldn't you want to JSON.stringify() your transformed post data? Like below:

const instance = axios.create({
    baseURL: 'api-url.com',
    transformRequest: [
        (data, headers) => {
            const encryptedString = encryptPayload(JSON.stringify(data));

            data = {
                SecretStuff: encryptedString,
            };

            return JSON.stringify(data);
        },
    ],  
});