elbywan / wretch

A tiny wrapper built around fetch with an intuitive syntax. :candy:
MIT License
4.79k stars 96 forks source link

form data and query issue when upgrading to v2 #142

Closed hieunm22 closed 2 years ago

hieunm22 commented 2 years ago

hi all before I upgrade the package to v2.1.1 these pieces of code work fine previous version is "wretch": "^1.7.10"

const CLIENT_BASE_URL = `${process.env.REACT_APP_BACKEND_BASE_URL}/api`

const request = wretch(CLIENT_BASE_URL)
export const uploadImage = (token: string, form: FormData) => request.url(EP.uploadAvatar)
            .auth(`Bearer ${token}`)
            .formData(form)  // Property 'formData' does not exist on type 'Wretch<unknown, unknown, undefined>'.ts(2339)
            .post()
            .json(uploadAvatarCallback)
            .catch(handleError)
export const loadResetPassword = (token: string, uid: number, tokenReset: string) => request.url(EP.resetPassword)
            .auth(`Bearer ${token}`)
            .headers({ "LostPasswordURL": "/lostpassword" })
            .query({ uid, token: tokenReset })  // Property 'query' does not exist on type 'Wretch<unknown, unknown, undefined>'.ts(2339)
            .get()
            .json(resetPasswordCallback)
            .catch(handleError)

so how to fix them in v2.1.1

thanks

elbywan commented 2 years ago

Hi @hieunm22,

To use the .query and .formData methods you need to use addons with wretch v2, please check the migration guide .