MCPcopy Create free account
hub / github.com/dailydotdev/apps / useRouterMemory

Function useRouterMemory

packages/shared/src/hooks/useRouterMemory.ts:39–68  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37};
38
39export const useRouterMemory = (): UseRouterMemory => {
40 const [state, dispatch] = useReducer(
41 routerMemoryReducer,
42 undefined,
43 createRouterInitialState,
44 );
45
46 return {
47 ...state,
48 push: async (url, as) => {
49 // in memory router only supports url and as as strings, so we can convert
50 // them to URL objects for internal handling, this is compatible with next/router
51 const urlObject = new URL(url, 'http://localhost');
52 const asObject = as ? new URL(as, 'http://localhost') : urlObject;
53
54 dispatch({
55 type: 'push',
56 payload: {
57 query: Object.fromEntries(urlObject.searchParams.entries()),
58 pathname: urlObject.pathname,
59 asPath: `${asObject.pathname}${
60 asObject.search ? `?${asObject.search}` : ''
61 }`,
62 },
63 });
64
65 return true;
66 },
67 };
68};

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected