Skip to content

Commit

Permalink
fix: prevent some check rerender plugin warning
Browse files Browse the repository at this point in the history
  • Loading branch information
LiJun committed Sep 1, 2020
1 parent 0e53f09 commit 10f3f01
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,22 @@ export default function init(initOpt: CubeState.InitOpt = {}) {
const updaters: Array<CubeState.Updater<MergedState>> = [];

function useStore<P>(selector: CubeState.StateSelector<MergedState, P>) {
const forceUpdate = useState({})[1];
const forceUpdate = useState(0)[1];

const updater: any = (
oldState: MergedState,
nextState: MergedState
) => {
const shouldUpdate = !equal(selector(oldState), selector(nextState));
shouldUpdate && forceUpdate({});
shouldUpdate && forceUpdate(n => n + 1);
updater.dirty = false;
};
updaters.push(updater);

useEffect(() => {
updater.ready = true;
// maybe state changed before mount
updater.dirty && forceUpdate({});
updater.dirty && forceUpdate(n => n + 1);
return () => {
updaters.splice(updaters.indexOf(updater), 1);
};
Expand Down

0 comments on commit 10f3f01

Please sign in to comment.