I learned that you can use macros to automatically decide which library based on which device is being used. This lets you avoid a lot of work when switching between boards.

#ifdef ESP8266
#include <ESP8266WiFi.h>
#else
#include <WiFi.h> // for ESP32
#endif