diff --git a/packages/react-debounce-render/src/index.tsx b/packages/react-debounce-render/src/index.tsx index 4d50ffa..9517a28 100644 --- a/packages/react-debounce-render/src/index.tsx +++ b/packages/react-debounce-render/src/index.tsx @@ -4,13 +4,16 @@ import { DebounceSettings } from 'lodash'; import hoistNonReactStatics from 'hoist-non-react-statics'; -function debounceRender(ComponentToDebounce: ComponentType, wait?: number, debounceArgs?: DebounceSettings): ComponentType { +function debounceRender(ComponentToDebounce: ComponentType, wait?: number, debounceArgs?: DebounceSettings, forceUpdateCondition?: (prevProps: T, nextProps: T, prevState: S, nextState: S) => boolean): ComponentType { class DebouncedContainer extends Component { public static readonly displayName = `debounceRender(${ ComponentToDebounce.displayName || ComponentToDebounce.name || 'Component' })`; updateDebounced = _debounce(this.forceUpdate, wait, debounceArgs); shouldComponentUpdate() { this.updateDebounced(); + if (typeof forceUpdateCondition === 'function' && forceUpdateCondition(this.props, nextProps, this.state, nextState)) { + this.updateDebounced.flush(); + } return false; }