Posts about React

8 posts

Back to the whole garden

  1. GRD 034 #149

    React callback refs: what, why, and why not

    Callback refs are a small React feature that solve real problems when object refs fall short. Here's how they work, when they shine, and when to avoid them.

  2. GRD 027 #62B

    When I reach for React's memo, useMemo and useCallback

    A lot of the memoisation in a React codebase does nothing, and some of it costs more than it saves. These are the few cases where I still use it.

  3. GRD 023 #A15

    How I type React components in TypeScript

    After a few years of typing React components I'm down to a handful of shapes, and I let the compiler infer the rest. React.FC isn't one of them anymore.

  4. GRD 021 #842

    Fixing a laggy search filter with useDeferredValue

    Typing into the filter above a long table felt like typing over a bad SSH connection. React 18 has a hook for exactly this and the fix was one line. Well, two.

  5. GRD 018 #3A7

    Moving my tests from Jest to Vitest

    Eight months ago I left the tests behind when I moved to Vite. Moving them took an evening. Reading them took longer, because most of them tested the wrong thing.

  6. GRD 016 #259

    Why React 18 runs your effects twice

    We upgraded to React 18 and every request in the dev tools showed up twice. React does that on purpose, as a test, and our effects were failing it.

  7. GRD 015 #13B

    Discriminated unions: the TypeScript feature I'd teach first

    Three booleans for one request gave us a spinner on top of an error message. One union with a status field fixed it, and now the compiler tells me when I forget a case.

  8. GRD 013 #14B

    Moving a Create React App project to Vite

    Create React App 5 landed this week after a year of waiting, and I still moved my side project to Vite. It took an evening, mostly spent renaming things.