check for the type of map

This commit is contained in:
nklhrstv 2020-10-18 23:44:06 +03:00
parent e14896deb0
commit ec43557dd8

View file

@ -24,7 +24,12 @@ const useModelState = ({ init, action, ...args }) => {
}, []);
React.useLayoutEffect(() => {
const onNewStateThrottled = throttle(() => {
setState(map(core.transport.getState(model)));
const state = core.transport.getState(model);
if (typeof map === 'function') {
setState(map(state));
} else {
setState(state);
}
}, timeout);
if (routeFocused) {
core.transport.on('NewState', onNewStateThrottled);