-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
Sad Gabi edited this page Jul 23, 2026
·
5 revisions
Once you have created your Chocola components, you can use them directly in HTML.
- Use the file name of your component (without the
.jsextension) as the HTML tag. - Component names use PascalCase (e.g.,
Counter,UserProfile,TodoItem).
Props are custom attributes you can pass to a component to provide values to render.
<Counter start="{5}" label="Clicks"></Counter>- Here,
startandlabelare props. - Props are passed as strings by default. Special props like numbers, booleans, or expressions must be wrapped in
{}to be converted automatically by Chocola, or you can convert them manually inside the component.
Props are available in the component context (ctx) during runtime:
function RUNTIME(self, ctx) {
ctx.count = ctx.start || 0;
const button = self.querySelector("button");
button.textContent = ctx.label || "Counter";
button.addEventListener("click", () => {
ctx.count++;
});
}Note:
ctxstores both props and component state.
<!-- index.html -->
<app>
<Counter title="Increment Count" start="{5}" label="Clicks"></Counter>
</app>After Chocola compiles the app:
<!-- dist/index.html -->
<app>
<div>
<button title="Increment Count">Clicks</button>
<div class="main">
<div class="number">5</div>
</div>
</div>
</app>The component renders with the provided prop values.