Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/guide/render-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,33 @@ render () {
}
```

## Return Values for Render Functions

In all of the examples we've seen so far, the `render` function has returned a single root VNode. However, there are alternatives.

Returning a string will create a text VNode, without any wrapping element:

```js
render() {
return 'Hello world!'
}
```

We can also return an array of children, without wrapping them in a root node. This creates a fragment:

```js
// Equivalent to a template of `Hello<br>world!`
render() {
return [
'Hello',
h('br'),
'world!'
]
}
```

If a component needs to render nothing, perhaps because data is still loading, it can just return `null`. This will be rendered as a comment node in the DOM.

## JSX

If we're writing a lot of `render` functions, it might feel painful to write something like this:
Expand Down