Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Theme changes automatically based on even/odd counter value.
import { h } from 'preact';
import { useState } from 'preact/hooks';
function ConditionalThemeCounter() {
const [count, setCount] = useState(0);
const isDark = count % 2 === 0;
return (
<div className={isDark ? 'dark-theme' : 'light-theme'}>
<h2>Counter: {count}</h2>
<button onClick={() => setCount(count + 1)}>+</button>
<button onClick={() => setCount(count - 1)}>-</button>
<button onClick={() => setCount(0)}>Reset</button>
</div>
);
}
export default ConditionalThemeCounter;Preact is a fast, lightweight JavaScript library for building user interfaces with a React-like API. It emphasizes small bundle size, performance, and compatibility with modern web standards while providing an easy transition for React developers.
Origin & Creator
Created by Jason Miller and first released in 2015, Preact was designed as a lightweight alternative to React for high-performance web applications.
Industrial Note
Preact excels in projects where bundle size, speed, and React compatibility are crucial, such as mobile-first web apps, embedded widgets, and highly interactive UIs.