强制组件更新 useForceUpdate

一个hook,完成组件的强制更新
更新于: 2023-07-17 09:42:13
import type { DispatchWithoutAction } from 'react';
import { useReducer } from 'react';

const useForceUpdate = () => {
  const [, dispatch] = useReducer((x) => x + 1, 0);
  return dispatch as DispatchWithoutAction;
};