Skip to content

Latest commit

 

History

History
56 lines (35 loc) · 2 KB

text.md

File metadata and controls

56 lines (35 loc) · 2 KB

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().

import { text } from "hyperapp"

// ...

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

Signature & Parameters:

text : (String | Number) -> VNode
Parameter Type Required? Notes
content any (sort of), but meaningfully only String or Number yes 💯
node DOM element prohibited ❌ This is for internal Hyperapp use only!
Return Value Type
virtual text node VNode

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

h("p", {}, text("You must construct additional pylons."))

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

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.