vuejs / vuejs/docs

Suggestion for updating Composables API documentation

Open
#2,434 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Vue
Stars
3.2k
Forks
5k
Avg merge
14d 17h
Merged PRs (30d)
1

Description

https://vuejs.org/guide/reusability/composables.html#return-values

You have probably noticed that we have been exclusively using ref() instead of reactive() in composables. The recommended convention is for composables to always return a plain, non-reactive object containing multiple refs. This allows it to be destructured in components while retaining reactivity:

While reviewing the documentation for the Composables API, I noticed that the suggested usage of ref() over reactive() might confuse beginners. Specifically, the "Return Values" section recommends using ref() over reactive() and returning a non-reactive object containing multiple refs. However, this may mislead beginners into thinking that reactive() is useless in Composables API.

In reality, we should freely choose whether to use ref() or reactive() depending on the need. reactive() is more suitable for managing objects or collections that contain multiple properties. While the article suggests using ref() mainly as it prevents the loss of reactivity when destructuring the object. Therefore, I suggest updating the documentation to clarify that the reactive() function is also important in the Composables API.

Furthermore, in writing Composables functions, we can use a reactive object and wrap it with a plain object while returning it, which still maintains reactivity. It is essential to ensure that the returned object retains reactivity even when destructured.

In conclusion, I suggest updating the documentation about using ref() and reactive() in Composables API to avoid any potential misunderstandings for beginners.

Thank you!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Open the linked Composables API documentation and read the Return Values section, including its discussion of ref() and reactive(). Update the explanation so beginners understand when either API is appropriate and how returned objects preserve reactivity when destructured; the section should no longer imply that reactive() is generally unsuitable for composables.

Written by the indexing model from the issue text.

Assessment

Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.