Sportsbook
A betting web app I built in Next.js. Hundreds of live prices move on screen at once, and it stays fluid on whatever phone the user has.
How it stays fluid
A betting screen is the worst case for a web app: hundreds of numbers changing every second, at the exact moment someone is trying to tap. Four problems every sportsbook runs into, and what I did about them. The live demo has a control panel to push it as hard as you like.
01
Hundreds of prices, one render each
The problem. Prices usually live in shared state. One price moves, the whole board re-renders, and a mid-range phone drops frames. The more markets on screen, the worse it gets.
The fix. Every market gets its own signal. A new price is pushed to that one signal, and only the buttons showing that market update. The board never hears about it.
02
The flash shouldn't cost a render
The problem. Users need to see a price move: green up, red down. Done with state, every flash is two extra renders, one to show it and one to clear it, multiplied by every price on screen.
The fix. The button compares the new price with the previous one and toggles a class straight on its DOM node. CSS does the animation. The price text is the only thing React renders.
03
A menu that slides even when the phone is busy
The problem. bet365's mobile menu pushes the whole page aside instead of covering it. Animate that with
left or width and the browser recalculates layout on every frame, on the same thread that
is busy handling live prices. The menu stutters exactly when the app is under load.
The fix. Move the page with transform only, so the GPU animates it on its own. Promote the layer
right before the animation and drop it right after, dim the page, ignore taps on it, and lock the body to
100dvh so nothing scrolls underneath.
04
A lighter app for a lighter phone
The problem. The same app runs on a flagship and on a three-year-old Android with 2 GB of memory. One experience for both means the cheap phone gets the janky version.
The fix. Ask the device. Under 4 GB of memory, match lists skip team crests. With 6 CPU cores or fewer, the betslip opens as a plain page instead of an animated bottom sheet. Everyone gets the fastest version their phone can carry.
The hooks come from
react-performance-hooks,
a TypeScript fork of Google's react-adaptive-hooks for current React, published on npm.
Team crests —
Betslip —