-
Notifications
You must be signed in to change notification settings - Fork 0
Managing Text
One of the most important parts of any website is text. And for dynamic websites, it's also important to have a solid way of updating text manually or reactively. Cardboard offers a few different ways of managing text.
The most basic type of text you can have is one that does not change. You can do this by:
- Passing text as a child:
const el = div('I\'m not supposed to change!');
el.text('But I can');
By passing the text directly as a child of the tag, it will not change unless manually changed.
Cardboard offers a very simple way of interpolating state values in strings.
This can be done by using the text
function,
by passing in an object state:
const st = state({ count: 0 });
const el = div(text('count: $count', st));
or an object of Consumables:
const count = state(0);
const el = div(text('count: $count', { count }));
Alternatively, this can also be done by using the tag.text()
method.
const st = state({ count: 0 });
const el = div().text('count: $count', st);
You can also add the state value (or any Consumable) directly.
const st = state({ count: 0 });
const el = div('count: ', st.count);
This Wiki is a work in progress, it's just me doing everything around here :P
If you read this and have some free time, and want to spend it helping me with the wiki or anything else, you're more than welcome!