See the issue and the test case with original fix in https://github.com/facebook/react/pull/14802.

We'll need to fix it properly, see https://github.com/facebook/react/pull/14802#issuecomment-463277621.
import type {ReactElement} from 'shared/ReactElementType';
type BasicStateAction<S> = (S => S) | S;
type Dispatch<A> = A => void;
type Update<A> = {
  action: A,
  next: Update<A> | null,
};
type UpdateQueue<A> = {
  last: Update<A> | null,
  dispatch: any,
};
type Hook = {
  memoizedState: any,
  queue: UpdateQueue<any> | null,
  next: Hook | null,
};
const {ReactCurrentDispatcher} = ReactSharedInternals;
const RE_RENDER_LIMIT = 25;
const emptyObject = {};
if (__DEV__) {
  Object.freeze(emptyObject);
}
let currentHookNameInDev: ?string;
function areHookInputsEqual(
  nextDeps: Array<mixed>,
  prevDeps: Array<mixed> | null,
) {
  if (prevDeps === null) {
    warning(
      false,