I ended up using a custom hook with useEffect()
. It actually isn't so messy after all.
export const functions = getFunctions(app);
export const useEmulator = () => {
useEffect(() => {
if (window?.location?.hostname === "localhost") {
connectFunctionsEmulator(functions, '127.0.0.1', 5001)
}
}, [])
}