acdlite / recompose

A React utility belt for function components and higher-order components.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

onlyUpdateForStateKeys?

mqklin opened this issue · comments

Is there an analogue for state?

Example:
@onlyUpdateForStateKeys('someOption') will add check for state.someOptions inside shouldComponentUpdate:

shouldComponentUpdate(undefined, nextState) {
  const {someOption} = this.state;
  if (someOption === nextState.someOption) {
    return false;
  }
}

Use case: if I use setState it will call render each time, even if someOption haven't been changed. The HOC will prevent this extra render call.

you have HOC(Component) state is in the component instance,
HOC have zero ability to access or change instance methods because of it's definition. It's a wrapper not mixin.

Sure. Thank you for the answer!