on master help sign in
fix: use functional state updates to handle multiple state mutations within the same render cycle
505ba41Matt Condon (shrugs)
src/bridge/store/history.js+6−3
@@ -16,12 +16,15 @@ function _useHistory(initialRoutes = []) {
16 throw BRIDGE_ERROR.INVALID_ROUTE;
16 throw BRIDGE_ERROR.INVALID_ROUTE;
17 }
17 }
18
18
19− setHistory([...history, { name, data }]);
19+ setHistory(history => [...history, { name, data }]);
20 },
20 },
21 popAndPush: (name, data = {}) =>
21 popAndPush: (name, data = {}) =>
22+ setHistory(history => [
22− setHistory([...history.slice(0, history.length - 1), { name, data }]),
23+ ...history.slice(0, history.length - 1),
24+ { name, data },
25+ ]),
23 pop: (count = 1) =>
26 pop: (count = 1) =>
24− setHistory([...history.slice(0, history.length - count)]),
27+ setHistory(history => [...history.slice(0, history.length - count)]),
25 peek: () => last(history),
28 peek: () => last(history),
26 size: history.length,
29 size: history.length,
27 includes: name => includes(history.map(r => r.name), name),
30 includes: name => includes(history.map(r => r.name), name),