Skip to content

Expand the page on render functions, especially their use of slots #712

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

Merged
merged 4 commits into from
Nov 28, 2020

Conversation

skirtles-code
Copy link
Contributor

@skirtles-code skirtles-code commented Nov 26, 2020

https://deploy-preview-712--vue-docs-next-preview.netlify.app/guide/render-function.html

I was involved in a couple of threads on the Vue Forum discussing how to use slots in render functions. From that it became clear that some key aspects aren't covered in the documentation. I've expanded the relevant section to mention some of the common use cases with explanations of some of the most common pitfalls.

I've added an earlier section explaining the creation of component VNodes. This introduces resolveComponent, which was already used in some of the examples but wasn't explained. However, my main objective was to make it more explicit that there are differences between creating VNodes for HTML elements and components. Otherwise the use of component VNodes in the section about slots comes a bit out of the blue.

I've also added a section about how to migrate <component is="name">. While it might seem obvious to someone who knows how to do it, I've seen several beginners get completely lost trying to write it as a render function. This section also introduces resolveDynamicComponent, which I felt needed to be mentioned somewhere.

const { h } = Vue

return h(
return Vue.h(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the only example that was written this way, so I've changed it to match the others.

@@ -164,6 +162,8 @@ h(
)
```

If there are no props then the children can usually be passed as the second argument. In cases where that would be ambiguous, `null` can be passed as the second argument to keep the children as the third argument.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to make this explicit so I could use it in the subsequent examples.

@skirtles-code skirtles-code marked this pull request as ready for review November 26, 2020 09:23
Copy link
Member

@bencodezen bencodezen left a comment

Choose a reason for hiding this comment

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

This is a fantastic enhancement @skirtles-code! Just have a few questions and suggestions for improvements.

Looking forward to getting this in the docs soon!

}
```

If we need to resolve a component by name then we can call `resolveComponent`:
Copy link
Member

Choose a reason for hiding this comment

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

When are some use cases for resolving a component by name?

You mention later that it's often unnecessary, so as a reader, I'm curious to know a scenario where knowing this helper method would be important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the next few sentences to try to clarify. I struggled to find a wording that wasn't a clumsy mess. It still doesn't flow as cleanly as I'd like but hopefully it's clear enough.

Copy link
Member

@bencodezen bencodezen left a comment

Choose a reason for hiding this comment

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

This is a great iteration @skirtles-code! Going to approve and merge so people can benefit from your work.

We can always submit improvements if people find anything confusing. Great work!

@bencodezen bencodezen merged commit ac5bec3 into vuejs:master Nov 28, 2020
nick-lai pushed a commit to nick-lai/docs-next that referenced this pull request Dec 2, 2020
…ots (vuejs#712)

* docs: expand the page on render functions, especially their use of slots

* Update src/guide/render-function.md

Co-authored-by: Ben Hong <[email protected]>

* Update src/guide/render-function.md

Co-authored-by: Ben Hong <[email protected]>

* docs: add a note about global registration and using resolveComponent

Co-authored-by: Ben Hong <[email protected]>
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