Pug
StartupJS supports the Pug templating language as an alternative to JSX. Pug uses indentation instead of angle brackets, which can make templates more concise. If you prefer JSX, you can skip this chapter entirely.
Pug works out of the box in StartupJS. You only need to configure your IDE for syntax highlighting: https://github.com/startupjs/startupjs#ide-configuration
Syntax basics
- Nesting is defined by indentation (no closing tags)
- Classes use
.className - IDs use
#id - Attributes go in parentheses
Tags and classes
Pug
JSX equivalent
Add classes with dot notation:
Attributes
With classes:
When a component has many props, use a multiline block:
In Pug, you do not need {} around JavaScript expressions. The value after = is treated as JavaScript.
Loops
Use each to render arrays:
Conditions
You can also use unless:
Interpolation
Use = to output a JavaScript expression as a child, or #{} for inline interpolation: