Your First App
Let's build a simple counter application to demonstrate Element's core features.
Step 1: Setup the State
/* App.ts */
import { createSignal } from "@dmnchzl/element";
function App() {
const [count, setCount] = createSignal(0);
}Step 1.5: Complexify the State
/* App.ts */
import { createComputed, createSignal } from "@dmnchzl/element";
function App() {
const [count, setCount] = createSignal(0);
const status = createComputed(() => {
if (count() >= 0) return "Positive";
return "Negative";
});
}Step 2: Create Helper Functions
Step 3: Create the Template
Step 4: Mount the App
What You've Built
This counter app demonstrates:
State management with signals using
createSignalEvent handling with button clicks
Computed values that automatically update based on state changes
Reactive templates that update the DOM automatically
Function-based components for clean code organization
The app is fully reactive - When you click the buttons, the counter value and status message update automatically without any manual DOM manipulation.
Key Concepts Demonstrated
Signals:
countstores the current value and notifies when it changesComputed Values:
statusautomatically recalculates whencountchangesEvent Handlers: Functions that modify state in response to user interactions
Template Binding: The
htmltemplate automatically updates when signals change
Last updated