...

/

3 presentation components

3 presentation components

We start with the presentation components because they’re the least complicated. To render a collection of particles, we need:

  • a stateless Particle
  • a stateless Particles
  • a proper App

None of them contain state, but App has to be a proper component so that we can use componentDidMount. We need it to attach D3 event listeners.

Particle

The Particle component is a circle. It looks like this:

Press + to interact
// src/components/Particles/Particle.jsx
import React from 'react';
const Particle = ({ x, y }) => (
<circle cx={x} cy={y} r="1.8" />
);
export default Particle;

It takes x and y coordinates and returns an SVG circle.

Particles

The Particles component isn’t much smarter – it returns a list of circles wrapped in a grouping element, like this:

Press + to interact
// src/components/Particles/index.jsx
import React from 'react';
import Particle from './Particle';
const Particles = ({ particles }) => (
<g>{particles.map(particle =>
<Particle key={particle.id}
{...particle} />
)}
</g>
);
export default Particles;
...
Access this course and 1400+ top-rated courses and projects.