Simple Counter - Inferno Typing CST Test
Loading…
Simple Counter — Inferno Code
Basic counter with increment, decrement, reset, and theme toggle.
import { render, Component } from 'inferno';
class Counter extends Component {
state = { count: 0, isDark: false };
increment = () => this.setState({ count: this.state.count + 1 });
decrement = () => this.setState({ count: this.state.count - 1 });
reset = () => this.setState({ count: 0 });
toggleTheme = () => this.setState({ isDark: !this.state.isDark });
render() {
return (
<div className={this.state.isDark ? 'dark-theme' : 'light-theme'}>
<h2>Counter: {this.state.count}</h2>
<div>
<button onClick={this.increment}>+</button>
<button onClick={this.decrement}>-</button>
<button onClick={this.reset}>Reset</button>
</div>
<button onClick={this.toggleTheme}>Switch to {this.state.isDark ? 'Light' : 'Dark'} Theme</button>
</div>
);
}
}
render(<Counter />, document.body);Inferno Language Guide
Inferno.js is an extremely fast, lightweight JavaScript library for building high-performance user interfaces. It uses a React-like API and Virtual DOM but is optimized for speed, small size, and predictable rendering.
Primary Use Cases
- ▸High-performance SPAs
- ▸Real-time dashboards and charts
- ▸Embedded widgets with small footprint
- ▸React-compatible environments needing speed
- ▸Apps requiring extremely fast client-side rendering
Notable Features
- ▸Ultra-fast Virtual DOM (faster than React in many benchmarks)
- ▸React-like components and lifecycle
- ▸Small bundle size (~9 KB)
- ▸Server-side rendering support
- ▸Partial React API compatibility
Origin & Creator
Created by Dominic Gannaway in 2016 as a high-performance alternative to React, with an emphasis on speed and small bundle size.
Industrial Note
Inferno is primarily used in performance-sensitive environments like financial dashboards, advertising tech, streaming interfaces, and embedded web widgets.
Quick Explain
- ▸Inferno provides a React-compatible API focused heavily on performance.
- ▸It uses a highly optimized Virtual DOM engine for minimal overhead.
- ▸Its architecture makes it suitable for real-time UIs, embedded widgets, and performance-critical apps.
Core Features
- ▸JSX + components
- ▸Virtual DOM diffing
- ▸Lifecycle hooks (componentDidMount, etc.)
- ▸Functional components supported
- ▸Efficient event handling system
Learning Path
- ▸Start with JSX + basic components
- ▸Understand VDOM diffing
- ▸Learn state & lifecycle methods
- ▸Practice high-performance techniques
- ▸Build SSR apps with `inferno-server`
Practical Examples
- ▸Simple counter component
- ▸High-frequency updating dashboard
- ▸Real-time stock ticker rendering
- ▸SSR-rendered landing page
- ▸Embedded widget with tiny bundle size
Comparisons
- ▸Faster than React - optimized VDOM
- ▸Smaller than React - tiny bundle
- ▸Less ecosystem than React/Vue
- ▸Similar API to React (easy migration)
- ▸Better suited for high-performance UIs
Strengths
- ▸One of the fastest UI libraries available
- ▸Very small and lightweight
- ▸Easy migration from React
- ▸Great SSR performance
- ▸Stable API with minimal overhead
Limitations
- ▸Smaller ecosystem than React/Vue
- ▸Some advanced React features not supported
- ▸Less community activity
- ▸Fewer tutorials and third-party libraries
- ▸Maintenance pace slower than big frameworks
When NOT to Use
- ▸When needing huge ecosystem support
- ▸When using React-specific hooks/features
- ▸When building massive enterprise apps
- ▸When team is unfamiliar with smaller libs
- ▸When SEO requires full React SSR ecosystem
Cheat Sheet
- ▸`Inferno.render(vnode, container)` - render app
- ▸JSX requires babel-plugin-inferno
- ▸Functional components recommended
- ▸Use `class extends Component` for stateful components
- ▸`inferno-create-element` for h() syntax
FAQ
- ▸Is Inferno faster than React?
- ▸Yes - its VDOM is extremely optimized.
- ▸Is Inferno compatible with React?
- ▸Partially - many React libs work, but not all.
- ▸Does Inferno support hooks?
- ▸No - only class and functional components.
- ▸Does Inferno support SSR?
- ▸Yes - with `inferno-server`.
- ▸Is the library still maintained?
- ▸Yes, but at a slower pace than major frameworks.
30-Day Skill Plan
- ▸Week 1: Components + JSX
- ▸Week 2: State mgmt + lifecycle
- ▸Week 3: Performance tuning
- ▸Week 4: SSR + hydration
- ▸Week 5: Embeddable micro-widgets
Final Summary
- ▸Inferno.js is a blazing-fast, lightweight alternative to React.
- ▸Its performance-focused Virtual DOM makes it ideal for real-time UIs.
- ▸React-style API lowers learning curve.
- ▸Best suited for dashboards, embedded widgets, and performance-heavy UIs.
- ▸Small ecosystem but extremely powerful in its niche.
Project Structure
- ▸src/components/ - UI components
- ▸src/index.js - app entry
- ▸public/index.html - mount point
- ▸babel.config.js - JSX transform
- ▸vite/webpack config - bundlers
Monetization
- ▸Performance-sensitive dashboards
- ▸Real-time analytics products
- ▸Embedded widget development
- ▸Migration from React to lightweight stacks
- ▸Optimization consulting
Productivity Tips
- ▸Use Babel plugin for JSX speed
- ▸Keep components pure
- ▸Use functional components
- ▸Enable production mode
- ▸Benchmark frequent updates
Basic Concepts
- ▸JSX + component rendering
- ▸Functional and class components
- ▸Props + state system
- ▸Virtual DOM re-rendering
- ▸Event handlers and lifecycle hooks