MCPcopy Index your code
hub / github.com/react-navigation/react-navigation / reset

Function reset

packages/core/src/StateUtils.js:180–202  ·  view source on GitHub ↗

* Resets all routes. * Note that this moves the index to the position to where the last route in the * stack is at if the param `index` isn't provided.

(state, routes, index)

Source from the content-addressed store, hash-verified

178 * stack is at if the param `index` isn't provided.
179 */
180 reset(state, routes, index) {
181 invariant(
182 routes.length && Array.isArray(routes),
183 'invalid routes to replace'
184 );
185
186 const nextIndex = index === undefined ? routes.length - 1 : index;
187
188 if (state.routes.length === routes.length && state.index === nextIndex) {
189 const compare = (route, ii) => routes[ii] === route;
190 if (state.routes.every(compare)) {
191 return state;
192 }
193 }
194
195 invariant(!!routes[nextIndex], 'invalid index %s to reset', nextIndex);
196
197 return {
198 ...state,
199 index: nextIndex,
200 routes,
201 };
202 },
203};
204
205export default StateUtils;

Callers

nothing calls this directly

Calls 1

invariantFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…