question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clarify all use cases for `key` in the guide

See original GitHub issue

Currently when I search for key on vuejs.org I’ll only get the “List Rendering” section. And this section only tells us key is useful when rendering lists, as a hint for element reuse.

Since it’s a generic mechanism for Vue to identify nodes, the key also has other uses that are not specifically tied to v-for, as we will see later in the guide.

I looked into the later part of the guide and found nothing about key. In fact it’s mentioned earlier in “Conditional Rendering - Controlling Reusable Elements with key. The problem here is this section only tells us key will affect element reuse but fail to mention this may happen to components as well. Later in the same section, in “Conditional Rendering - v-if vs v-show, it says child components are destroyed and re-created during toggles, which may make this more confusing:

v-if is “real” conditional rendering because it ensures that event listeners and child components inside the conditional block are properly destroyed and re-created during toggles.

According to my current understanding, key is an essential hint for Vue across the whole system. Components and elements are all possible to be reused during conditional or list rendering. I think it would be better to give key a separate section to clarify all possible situations when we need to use key because of the mechanisms under the hood, in one place.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Justineocommented, Apr 18, 2019

image

What if we put this section highlighted and move it to the top (like above)? This may help ensure people get the general idea of key’s usage. And we need to rephrase a little bit because key is mentioned in Conditional Rendering section which is before List Rendering. (Maybe the hint for key can be added in the front of Controlling Reusable Elements with key too.)

1reaction
chrisvfritzcommented, Nov 3, 2017

I wouldn’t say how key works is an implementation detail, because there are many cases (like with <keep-alive>) where I would only know when/why I’d use key if I understand how it works. I can see a page on object constancy in general being useful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is a Use Case & How To Write One | Wrike
When presented in written form, a use case can be a helpful piece of project documentation. Use cases are a common requirements artifact,...
Read more >
Use Cases | Usability.gov
A use case is a written description of how users will perform tasks on your website. It outlines, from a user's point of...
Read more >
What Is a Use Case? (With Key Elements and an Example)
A use case is a text-based document that describes how one person interacts with a system to accomplish a particular goal. It's typically...
Read more >
Use Cases - what Every Project Manager Should Know - PMI
Use case modeling provides an effective technique to capture customer ... The key components of use cases are the system, actors, and use...
Read more >
UML Use Case Diagram Tutorial - YouTube
Learn how to make Use Case Diagrams in this tutorial. Both beginners and intermediate UML diagrammers will find all the necessary training ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found