Inferno Guide
Table of Contents
- Installation
- Basic Usage
- Engine Initialization
- Custom Configuration
- Preset Usage
- Component Pattern
- TypeScript Example
Installation
Install the Inferno wrapper and the tsParticles engine via npm:
npm install @tsparticles/inferno tsparticlesOptionally install the slim preset for a smaller bundle:
npm install @tsparticles/slimBasic Usage
The @tsparticles/inferno package exports two items: ParticlesProvider and Particles. Wrap your particle components with ParticlesProvider which accepts an init callback for engine setup, then use <Particles> to render the particle canvas.
import { render } from "inferno";
import { Particles, ParticlesProvider } from "@tsparticles/inferno";
import { loadSlim } from "@tsparticles/slim";
const options = {
fpsLimit: 60,
particles: {
number: { value: 80 },
color: { value: "#00d4ff" },
shape: { type: "circle" },
opacity: { value: 0.6 },
size: { value: { min: 2, max: 5 } },
links: {
enable: true,
distance: 150,
color: "#00d4ff",
opacity: 0.3,
width: 1,
},
move: {
enable: true,
speed: 1.5,
direction: "none",
random: true,
outModes: { default: "bounce" },
},
},
background: { color: "#0d1117" },
};
function App() {
return (
<ParticlesProvider
init={async (engine) => {
await loadSlim(engine);
}}
>
<Particles id="tsparticles" options={options} />
</ParticlesProvider>
);
}
render(<App />, document.getElementById("app"));ParticlesProvider must be an ancestor of every <Particles> component. It initializes the engine once and provides it via context to all children.
Engine Initialization
The ParticlesProvider accepts an init prop that receives the engine instance. This is where you load the features, shapes, presets, or updaters your app needs.
// Lightweight — circle particles, basic movement, links
<ParticlesProvider init={async engine => {
const { loadSlim } = await import("@tsparticles/slim");
await loadSlim(engine);
}}>
// Full feature set — all shapes, interactions, effects
<ParticlesProvider init={async engine => {
const { loadFull } = await import("tsparticles");
await loadFull(engine);
}}>
// Preset-specific — confetti, fireworks, snow, stars
<ParticlesProvider init={async engine => {
const { loadConfettiPreset } = await import("@tsparticles/preset-confetti");
await loadConfettiPreset(engine);
}}>Using dynamic import() inside the callback enables code splitting: the preset or feature modules are loaded only when the particle component mounts.
Custom Configuration
Below is a fully featured configuration with interactivity, multiple shape types, and a dark gradient background.
import { render } from "inferno";
import { Particles, ParticlesProvider } from "@tsparticles/inferno";
import type { ISourceOptions } from "@tsparticles/engine";
const options: ISourceOptions = {
fullScreen: { enable: true, zIndex: -1 },
fpsLimit: 60,
particles: {
number: {
value: 60,
density: { enable: true, width: 800, height: 800 },
},
color: {
value: ["#ff6b6b", "#feca57", "#48dbfb", "#ff9ff3", "#54a0ff"],
},
shape: {
type: ["circle", "triangle", "polygon"],
options: {
polygon: { sides: 6 },
},
},
opacity: { value: { min: 0.4, max: 0.8 } },
size: { value: { min: 3, max: 8 } },
links: {
enable: true,
distance: 200,
color: "#ffffff",
opacity: 0.15,
width: 1,
},
move: {
enable: true,
speed: 2,
direction: "none",
random: true,
straight: false,
outModes: { default: "out" },
},
},
interactivity: {
events: {
onHover: { enable: true, mode: "attract" },
onClick: { enable: true, mode: "repulse" },
},
modes: {
attract: { distance: 200, duration: 0.4, factor: 1 },
repulse: { distance: 200, duration: 0.4 },
},
},
background: { color: "#0f0f23" },
};
function App() {
return (
<ParticlesProvider
init={async (engine) => {
const { loadSlim } = await import("@tsparticles/slim");
await loadSlim(engine);
}}
>
<Particles id="tsparticles" options={options} />
</ParticlesProvider>
);
}
render(<App />, document.getElementById("app"));Preset Usage
The @tsparticles/configs package offers pre-built configurations that you can pass straight to the options prop. Combine them with the corresponding preset loader in the ParticlesProvider init callback.
import { render } from "inferno";
import { Particles, ParticlesProvider } from "@tsparticles/inferno";
import configs from "@tsparticles/configs";
function App() {
return (
<ParticlesProvider
init={async (engine) => {
const { loadFull } = await import("tsparticles");
await loadFull(engine);
}}
>
<Particles id="tsparticles" options={configs.confetti} />
</ParticlesProvider>
);
}
render(<App />, document.getElementById("app"));You can swap configs.confetti with any available preset: configs.basic, configs.fireworks, configs.snow, configs.stars, etc.
Component Pattern
For larger applications, structure your particle logic into a dedicated component with a particlesLoaded callback for accessing the Container instance.
import { render, Component } from "inferno";
import { Particles, ParticlesProvider } from "@tsparticles/inferno";
import type { Container, ISourceOptions } from "@tsparticles/engine";
const options: ISourceOptions = {
fpsLimit: 60,
particles: {
number: { value: 80 },
color: { value: "#00d4ff" },
shape: { type: "circle" },
opacity: { value: 0.6 },
size: { value: { min: 2, max: 5 } },
links: {
enable: true,
distance: 150,
color: "#00d4ff",
opacity: 0.3,
width: 1,
},
move: {
enable: true,
speed: 1.5,
outModes: { default: "bounce" },
},
},
interactivity: {
events: {
onHover: { enable: true, mode: "grab" },
onClick: { enable: true, mode: "push" },
},
modes: {
grab: { distance: 180, links: { opacity: 0.6 } },
push: { quantity: 3 },
},
},
background: { color: "#0a0a1a" },
};
class ParticlesBackground extends Component {
private container?: Container;
handleParticlesLoaded(container?: Container) {
this.container = container;
console.log("Particles loaded:", container?.id);
}
render() {
return (
<ParticlesProvider
init={async (engine) => {
const { loadSlim } = await import("@tsparticles/slim");
await loadSlim(engine);
}}
>
<Particles id="tsparticles" options={options} particlesLoaded={this.handleParticlesLoaded} />
</ParticlesProvider>
);
}
}
function App() {
return (
<div>
<h1 style={{ position: "relative", zIndex: 1, color: "#fff" }}>tsParticles + Inferno</h1>
<ParticlesBackground />
</div>
);
}
render(<App />, document.getElementById("app"));TypeScript Example
Here is a complete, typed Inferno application with a responsive particle configuration and full-screen background.
import { render } from "inferno";
import { Particles, ParticlesProvider } from "@tsparticles/inferno";
import type { Container, Engine, ISourceOptions } from "@tsparticles/engine";
const particlesOptions: ISourceOptions = {
fullScreen: { enable: true, zIndex: -1 },
fpsLimit: 60,
particles: {
number: { value: 80, density: { enable: true } },
color: { value: "#6366f1" },
shape: { type: "circle" },
opacity: { value: { min: 0.3, max: 0.7 } },
size: { value: { min: 2, max: 6 } },
links: {
enable: true,
distance: 160,
color: "#6366f1",
opacity: 0.25,
width: 1,
},
move: {
enable: true,
speed: 1.2,
direction: "none",
random: false,
straight: false,
outModes: { default: "bounce" },
},
},
interactivity: {
events: {
onHover: { enable: true, mode: "grab" },
onClick: { enable: true, mode: "push" },
},
modes: {
grab: { distance: 180, links: { opacity: 0.6 } },
push: { quantity: 3 },
},
},
background: { color: "#0a0a1a" },
};
function handleInit(engine: Engine): Promise<void> {
return import("@tsparticles/slim").then(({ loadSlim }) => loadSlim(engine));
}
function handleParticlesLoaded(container?: Container): void {
console.log("tsParticles container ready:", container?.id);
}
function App() {
return (
<ParticlesProvider init={handleInit}>
<div style={{ position: "relative", zIndex: 1, color: "#fff", textAlign: "center", paddingTop: "2rem" }}>
<h1>tsParticles + Inferno</h1>
<p>Full TypeScript integration</p>
</div>
<Particles id="tsparticles" options={particlesOptions} particlesLoaded={handleParticlesLoaded} />
</ParticlesProvider>
);
}
render(<App />, document.getElementById("app"));You now have everything needed to integrate tsParticles into an Inferno application. Each example is self-contained and ready to be copied into your project.
