Use React’s class-only getSnapshotBeforeUpdate lifecycle from function components, via a tiny wrapper.
getSnapshotBeforeUpdate