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

feat(nuxt3): allow providing a ref as default value #4326

Merged
merged 1 commit into from
Apr 13, 2022
Merged

Conversation

danielroe
Copy link
Member

πŸ”— Linked issue

resolves nuxt/nuxt#12931

❓ 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

This PR allows the default values for useCookie, useState, useAsyncData and useFetch to return a ref, which will be reused in the composable rather than recreated.

So, for example:

const someRef = ref('test value')
const cookie = useCookie('value', () => someRef)
console.log(someRef === cookie) // true

However, this is to enable advanced use cases only and users should not assume that the factory function will be run. In many cases the factory function is not run, such as when state is deserialized from payload.

πŸ“ Checklist

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

@danielroe danielroe added enhancement New feature or request nuxt3 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing labels Apr 13, 2022
@danielroe danielroe requested a review from pi0 April 13, 2022 13:27
@danielroe danielroe self-assigned this Apr 13, 2022
@netlify
Copy link

netlify bot commented Apr 13, 2022

βœ… Deploy Preview for nuxt3-docs ready!

Name Link
πŸ”¨ Latest commit ff64122
πŸ” Latest deploy log https://app.netlify.com/sites/nuxt3-docs/deploys/6256cfb860fe25000977024a
😎 Deploy Preview https://deploy-preview-4326--nuxt3-docs.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 settings.

@pi0 pi0 merged commit ee93659 into main Apr 13, 2022
@pi0 pi0 deleted the feat/default-ref branch April 13, 2022 17:41
@danielroe danielroe added the 3.x label Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3.x enhancement New feature or request nuxt3 🍰 p2-nice-to-have Priority 2: nothing is broken but it's worth addressing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow passing refs to useState and useCookie
2 participants