From 6b20949f68e8ff4a6d024d58c3a56de1f4430b92 Mon Sep 17 00:00:00 2001 From: nklhrstv Date: Thu, 7 Jul 2022 22:38:11 +0300 Subject: [PATCH] onNewState changes the state based on which model actually changes --- src/common/useModelState.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/common/useModelState.js b/src/common/useModelState.js index c552e7455..2b9584874 100644 --- a/src/common/useModelState.js +++ b/src/common/useModelState.js @@ -92,7 +92,7 @@ const useModelState = ({ action, ...args }) => { }; }, []); React.useInsertionEffect(() => { - const onNewStateThrottled = throttle(async (models) => { + const onNewState = async (models) => { if (models.indexOf(model) === -1) { return; } @@ -103,11 +103,12 @@ const useModelState = ({ action, ...args }) => { } else { setState(state); } - }, timeout); + }; + const onNewStateThrottled = throttle(onNewState, timeout); if (routeFocused) { core.transport.on('NewState', onNewStateThrottled); if (mountedRef.current) { - onNewStateThrottled.call(); + onNewState([model]); } } return () => {