Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Persists counter value in localStorage using Solid.js signals.
import { createSignal, onMount } from 'solid-js';
function Counter() {
const [count, setCount] = createSignal(0);
const [isDark, setIsDark] = createSignal(false);
onMount(() => {
const savedCount = localStorage.getItem('count');
if (savedCount) setCount(parseInt(savedCount, 10));
const savedTheme = localStorage.getItem('isDark');
if (savedTheme) setIsDark(savedTheme === 'true');
});
const updateAndSave = (newCount) => {
setCount(newCount);
localStorage.setItem('count', newCount);
};
return (
<div class={isDark() ? 'dark-theme' : 'light-theme'}>
<h2>Counter: {count()}</h2>
<button onClick={() => updateAndSave(count() + 1)}>+</button>
<button onClick={() => updateAndSave(count() - 1)}>-</button>
<button onClick={() => updateAndSave(0)}>Reset</button>
<button onClick={() => {
setIsDark(!isDark());
localStorage.setItem('isDark', !isDark());
}}>Toggle Theme</button>
</div>
);
}
export default Counter;SolidJS is a fast, reactive JavaScript library for building user interfaces using fine-grained reactivity and a compile-time optimized rendering model. It emphasizes performance, predictable state updates, and minimal abstraction.
Origin & Creator
Created by Ryan Carniato and released publicly in 2020, inspired by Knockout, React, and fine-grained reactivity systems.
Industrial Note
SolidJS excels in high-performance UI applications, real-time dashboards, embedded widgets, and scenarios requiring extremely fast updates.