Good Magic and Bad Magic

Good magic just works. It’s invisible and you quickly forget that it’s there.

Bad magic works sometimes. It’s mysterious and hard to understand.

Good programming abstractions are the right kind of magic. You can depend on them and build on top of them with confidence.

Bad programming abstractions are the wrong kind of magic. It’s equally a mystery when it works as when it doesn’t work. They’re leaky and you end up spending more time cleaning up after the magic than benefiting from it.

  • Keeping React Hooks With Usestate in Sync With Props

    An annoying footgun with React hooks is using useState with an initial value from props. It might appear like useState will be called each render, but it doesn’t (the bad kind of magic). Instead, it will run once when the component is initially rendered and you will run into stale read bugs when you rely on props to re-render the component with updated data.