Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow pathParams to be reactive getter #39

Merged

Conversation

mattmess1221
Copy link
Contributor

πŸ”— Linked issue

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSDoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

pathParams didn't support being passed via

const id = ref("0")
useApiData("endpoint/{id}", { 
  pathParams: { id }
})

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@netlify
Copy link

netlify bot commented Aug 25, 2023

βœ… Deploy Preview for nuxt-api-party ready!

Name Link
πŸ”¨ Latest commit af864a6
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt-api-party/deploys/64e9d06a6b4d9c0009039e1f
😎 Deploy Preview https://deploy-preview-39--nuxt-api-party.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@johannschopplich johannschopplich changed the title fix: allow pathParams to be a object ref fix: allow pathParams to be reactive getter Aug 26, 2023
@johannschopplich
Copy link
Owner

johannschopplich commented Aug 26, 2023

Thanks for the PR. I get your point. It is a valid one. But I intend do keep the reactive logic as close to Nuxt/VueUse as possible. For nested reactive assignments, a ref or getter function should be used. The latter one wasn't supported before, which will be fixed by this PR.

const id = ref(10)

const data = await $myApi('foo/{id}', {
  pathParams: () => ({
    id: id.value
  })
})

Although this syntax is more verbose, it aligns more with VueUse composables. I have added an example to the documentation and hope that's fine for your use-case.

@johannschopplich johannschopplich merged commit 41bd30e into johannschopplich:main Aug 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants