@navinc/base-react-components
Version:
Nav's Pattern Library
24 lines • 1.05 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useLayoutEffect, useState } from 'react';
// eslint-disable-next-line no-restricted-imports -- only allowed here - this extends render to include our required providers
import { createMemoryHistory } from 'history';
import { Router } from 'react-router-dom';
export const AppContextMemoryRouter = ({ initialEntries, initialIndex, }) => {
const history = createMemoryHistory({
initialEntries,
initialIndex,
});
const MemoryRouter = ({ children, basename }) => {
const [state, setState] = useState({
action: history.action,
location: history.location,
});
useLayoutEffect(() => history.listen((location) => setState({
action: history.action,
location,
})), [setState]);
return (_jsx(Router, { basename: basename, location: state.location, navigator: history, children: children }));
};
return [MemoryRouter, history];
};
//# sourceMappingURL=app-context-memory-router.js.map