Skip to content
This repository was archived by the owner on Apr 6, 2023. It is now read-only.

feat: useNuxtData composable #9262

Merged
merged 25 commits into from
Dec 5, 2022
Merged

feat: useNuxtData composable #9262

merged 25 commits into from
Dec 5, 2022

Conversation

mahdiboomeri
Copy link
Contributor

@mahdiboomeri mahdiboomeri commented Nov 22, 2022

πŸ”— Linked issue

resolves nuxt/nuxt#15582
resolves nuxt/nuxt#14924

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 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)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

It introduces a new useNuxtData composable.

πŸ“ Checklist

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

@codesandbox
Copy link

codesandbox bot commented Nov 22, 2022

CodeSandbox logoCodeSandbox logoΒ  Open in CodeSandbox Web Editor | VS Code | VS Code Insiders

@atinux
Copy link
Member

atinux commented Nov 24, 2022

I really like this idea of optimistic UI.

I would personally rename it to getNuxtData().

Happy to get feedback also from other team member

@pi0
Copy link
Member

pi0 commented Nov 24, 2022

Related PR to access data: #7569

I think useNuxtData makes sense (comparing to useData() in other PR and getNuxtData()). We use use* prefix for composables that use implicit context/CAPI. And also nuxt in the name makes sense.

Comparing to #7569:

  • We could support key param to get one data
  • We should return a ref IMO to allow changing value by key

@mahdiboomeri
Copy link
Contributor Author

Thanks for looking into this!
I've updated the PR base on @pi0's suggestion

@pi0 pi0 mentioned this pull request Nov 28, 2022
7 tasks
@mahdiboomeri mahdiboomeri requested a review from pi0 December 2, 2022 20:29
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ’―

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not call useNuxtData within a request handler. We need to update the docs here.

@pi0 pi0 requested a review from danielroe December 5, 2022 12:21
Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks ❀️

pi0 and others added 2 commits December 5, 2022 13:54
@pi0
Copy link
Member

pi0 commented Dec 5, 2022

Thanks again dear @mahdiboomeri <3 A short explainer of recent changes:

  • useNuxtData requires an explicit key. This makes usage easier and also explicit for keys (excluding auto generated keys). Also allows more flexibility to change the implementation in the future.
  • Return value of useNuxtData is { data: Ref }. This makes it consistent with other data composables and also ensures to have upward compatibility to add any other fields related to data
  • Docs updated as daniel suggested to cache value of useNuxtData() outside of handler. However we restore context and it is always available on client-side, it cannot always work in async conditions where nuxt context is lost. It also makes examples easier to read as we call it once.

@pi0 pi0 merged commit 9c478ee into nuxt:main Dec 5, 2022
@mahdiboomeri mahdiboomeri deleted the feat/nuxt-data branch December 5, 2022 14:13
@pi0 pi0 mentioned this pull request Dec 15, 2022
6 tasks
@danielroe danielroe added the 3.x label Jan 19, 2023
@danielroe danielroe mentioned this pull request Jan 20, 2023
danielroe added a commit that referenced this pull request Jan 21, 2023
Co-authored-by: Daniel Roe <daniel@roe.dev>
Co-authored-by: Pooya Parsa <pooya@pi0.io>
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accessing async data cache object with a new composable useData composable
4 participants