query-string#StringifiableRecord TypeScript Examples
The following examples show how to use
query-string#StringifiableRecord.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: schools.ts From po8klasie with GNU General Public License v3.0 | 6 votes |
useSchoolsData = (filtersValues: StringifiableRecord, defaultQuery: StringifiableRecord) => {
const endpointUrl = qs.stringifyUrl(
{
url: '/institutions',
query: {
...filtersValues,
...defaultQuery,
},
},
{ skipEmptyString: true, arrayFormat: 'comma' },
);
return useSWR(endpointUrl, (key) => fetcher<RailsApiSchoolsDataResponse>(key));
}
Example #2
Source File: SearchView.tsx From po8klasie with GNU General Public License v3.0 | 6 votes |
SearchView: FC = () => {
const router = useRouter();
const { searchView: searchViewConfig } = useProjectConfig();
const { defaultQuery } = searchViewConfig as SearchViewConfig;
const { filtersValues, setFiltersValues } = useFiltersValues();
const debouncedFiltersValues = useDebouncedValue(filtersValues, 300);
const { data } = useSchoolsDataRails(debouncedFiltersValues as StringifiableRecord, defaultQuery);
const updateQueryString = useCallback(
(obj: StringifiableRecord) => {
router.replace(
qs.stringifyUrl(
{
url: router.asPath,
query: obj,
},
{ skipEmptyString: true, arrayFormat: 'comma' },
),
);
},
[router],
);
useDeepCompareEffect(() => {
updateQueryString(filtersValues as StringifiableRecord);
}, [filtersValues]);
return (
<div>
<FiltersRow filtersValues={filtersValues} setFiltersValues={setFiltersValues} />
<SchoolsBrowser results={data ? data.results : []} />
</div>
);
}