A simple rating component that demonstrates essential React concepts and patterns. This project showcases how fundamental React features work together to build interactive user interfaces.
Live demo: https://felipeozalmeida.github.io/rating-ui-react/
This rating UI implementation covers these key React concepts:
- JSX - Writing component markup
- Components - Building reusable UI pieces
- Styling - Applying global, scoped, and dynamic styles
- Props & State - Managing data flow and component state
- Events - Handling user interactions
- Lists - Rendering dynamic collections
- Conditional Rendering - Showing/hiding UI based on conditions
- Children Components - Component composition patterns
- Effects - Managing side effects and lifecycle
- Portals - Rendering outside the component tree (e.g. modals)
- Accessibility (a11y) - Keyboard navigation, focus management, ARIA roles, and feedback
First, make sure you have a suitable Node.js version installed. For reference, this project was developed with:
- node v24.18.0
- npm v11.16.0
Install dependencies with your favorite package manager. Assuming it's npm:
npm installThen you're ready to go with:
npm run devEvery spec names the environment it runs in with a qualifier in its filename,
such as Rating.dom.spec.tsx. The environments are ordered by fidelity, from
the cheapest to the most faithful:
| qualifier | runs in |
|---|---|
.node. |
Node, with no DOM (.ts only) |
.dom. |
the default DOM implementation, currently happy-dom |
.happy-dom. |
happy-dom |
.jsdom. |
jsdom |
.browser. |
real Chromium through Playwright, with layout and CSS |
Pick the cheapest one that can see what the spec tests:
.node.for logic that doesn't touch the DOM.dom.for rendering, props, state, events and ARIA attributes, in components and hooks. Hooks need a DOM too, because rendering them goes through React DOM..happy-dom.or.jsdom.only when the spec depends on that implementation.browser.for what the emulators can't see: layout and sizes, real CSS, including what it hides from view and from assistive technology, focus that depends on what's rendered, and workers
Some behaviour no environment here can see, such as what a screen reader announces. Check that by hand with one, such as VoiceOver or NVDA.
Watch every new spec fail before you make it pass, so you know it can fail.
When you're unsure whether an emulator can see a bug, break the component on
purpose, for example by hiding an element with CSS, and run the spec in both
environments. If only .browser. turns red, the spec belongs there.
A spec without a qualifier fails lint.
Vitest, TypeScript and ESLint pick up both .spec. and .test. files. Wherever
a config lists both, spec comes first, as in *.{spec,test}.{ts,tsx}.
Browser Mode specs run in Chromium through Playwright, which has to be downloaded once:
npm run test:install
npm run test:unitOn Linux, Chromium also needs some system libraries. On Debian, Ubuntu and their derivatives, Playwright can install them for you:
npm run test:install -- --with-depsThis uses apt, so it fails on other distributions. There, install Chromium's dependencies with your own package manager instead.