Controlled and uncontrolled components

August 28th, 2024//Ep. 194

Sam and Ryan discuss controlled and uncontrolled components in React. They talk about how uncontrolled components can be thought of as components that manage their own internal state, why you should model your complex React components after the simpler APIs of native HTML elements like inputs, why you shouldn't try to make components that are both controlled and uncontrolled, and why making a new component boundary is sometimes all you need to make your custom components behave more predictably.

Timestamps

  • Intro
  • What are controlled and uncontrolled components?
  • How to change a component from uncontrolled to controlled
  • How do you decide when to use a controlled or uncontrolled component?
  • Sortable table example and a single source of truth
  • Is it always either controlled or uncontrolled?
  • Color picker example and not exposing internal state
  • Sortable list example with Framer Motion
  • Component boundaries and wearing two hats: the library author vs. library consumer
  • How do you know if you are using the wrong approach?