Back to Hyperapp

`text()`

docs/api/text.md

2.0.222.0 KB
Original Source

text()

Definition:

A function that creates a virtual DOM node (VNode) out of a given value.

Import & Usage:

You'll normally use it with h().

js
import { text } from "hyperapp"

// ...

h("p", {}, text(content))

Signature & Parameters:

elm
text : (String | Number) -> VNode
ParameterTypeRequired?Notes
contentany (sort of), but meaningfully only String or Numberyes :100:
nodeDOM elementprohibited :x:This is for internal Hyperapp use only!
Return ValueType
virtual text nodeVNode

You would use text() to insert regular text content into your views.

js
h("p", {}, text("You must construct additional pylons."))
<!-- In the videogame "StarCraft", the alien race known as the Protoss use special structures called pylons to power their buildings. -->

Of course, this may include anything relevant from the current state.

js
h("p", {}, text(state.message))

text() exists as the way of defining text nodes such that Hyperapp's implementation is kept simpler than it otherwise would have been.


Parameters

content

While content can technically be anything, what will actually be used for the content of the VDOM element will be the stringified version of content. So, using actual strings and numbers makes a lot of sense but using arrays will probably be formatted in a way you don't want and objects won't work well at all.