UNPKG

@etsoo/react

Version:

TypeScript ReactJs UI Independent Framework

34 lines (33 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useSearchParamsEx = useSearchParamsEx; exports.useSearchParamsEx1 = useSearchParamsEx1; const shared_1 = require("@etsoo/shared"); const react_router_1 = require("react-router"); function parseData(template, sp) { const paras = Object.fromEntries(Object.keys(template).map((key) => { const type = template[key]; return [key, type.endsWith("[]") ? sp.getAll(key) : sp.get(key)]; })); // Return return shared_1.DomUtils.dataAs(paras, template, false); } /** * Extended useSearchParams of react-router-dom * Provide exact type data */ function useSearchParamsEx(template) { // Get parameters const [sp] = (0, react_router_1.useSearchParams)(); return parseData(template, sp); } /** * Extended useSearchParams of react-router-dom * Provide exact type data and setSearchParams function */ function useSearchParamsEx1(template) { // Get parameters const [sp, setSearchParams] = (0, react_router_1.useSearchParams)(); // Return return [parseData(template, sp), setSearchParams]; }