Home > Enterprise >  Approch for use rtk quey hook for sending request when ever params are exist not always?
Approch for use rtk quey hook for sending request when ever params are exist not always?

Time:01-12

I use rtk quey and mutations in my app and i use hooks in my components that i pass some params to them by props or context .i want to they send request when ever props is exist not always send request to backend

const packageDetail = useGetPackageDetailQuery({ id })

when id is exist just send .is there a way?

CodePudding user response:

You can use skipToken or the skip option:

const packageDetail = useGetPackageDetailQuery(id ? { id } : skipToken)

or

const packageDetail = useGetPackageDetailQuery({ id }, { skip: !id })
  •  Tags:  
  • Related