Modern web apps feel “alive” because the UI updates automatically when data changes.
This is called reactivity.
Most people think you need frameworks like React or Vue for this — but you don’t.
What Is Reactivity?
Reactivity means:
When state changes → the UI updates automatically
Example:
- User types text → preview updates
- Counter increases → number on screen changes
- Checkbox toggles → text appears/disappears
No manual DOM updates everywhere.
Step 1: Basic HTML
<!DOCTYPE html>
<html>
<head>
<title>Reactive Page</title>
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src='https://signel.onrender.com/signel.js'></script>
</head>
<body>
<h2>Live Preview</h2>
<input id="live" />
<p>Preview: <span id="preview"></span></p>
<script src="app.js"></script>
</body>
</html>
Step 2: Create Reactive State
In app.js, we'll create reactive state
// making reactive state
const live = state({
text: ''
});
So we create state for watching and making react when that state changes
// jQuery event → update Signel state
$('#live').on('input', function () {
live.text = $(this).val()
})
When user types state will automatically change
// Signel render → update DOM using jQuery
render(() => {
$('#preview').text(live.text)
})
And finally updated state will be displayed in DOM
Full codes of app.js:
const live = state({
text: ''
})
// jQuery event → update Signel state
$('#live').on('input', function () {
live.text = $(this).val()
})
// Signel render → update DOM using jQuery
render(() => {
$('#preview').text(live.text)
})
Top comments (0)