react-model icon indicating copy to clipboard operation
react-model copied to clipboard

Improve useStore's performance on huge dataset

Open ArrayZoneYour opened this issue 6 years ago • 0 comments

Every useStore create a setState now. The cost of communicator middleware will be expensive when the new state passed in setState is huge and the number of components(use useStore hooks) is big.

Enhance:

// before
const useStore = (modelName: string, depActions?: string[]) => {
  const [, setState] = useState(Global.State[modelName].state)
  // ...
}

// expected
const useStore = (modelName: string, depActions?: string[]) => {
  // If Context exist
  const { [modelName]: { setState } } = useContext(GlobalContext)
  // If not
  const [, setState] = useState(Global.State[modelName].state)
  // ...
}

ArrayZoneYour avatar Feb 17 '19 05:02 ArrayZoneYour