@etsoo/react
Version:
TypeScript ReactJs UI Independent Framework
18 lines (17 loc) • 539 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.useLocationState = useLocationState;
const react_router_dom_1 = require("react-router-dom");
/**
* Location state
* @param T Type of state
* @returns State
* @throws Error if state is null or undefined
*/
function useLocationState() {
const location = (0, react_router_dom_1.useLocation)();
if (location.state == null) {
throw new Error(`useLocationState: ${location.pathname} state is required`);
}
return location.state;
}