@resourge/react-fetch
Version:
[](LICENSE)
44 lines (41 loc) • 1.03 kB
JavaScript
/**
* react-fetch v1.41.3
*
* Copyright (c) resourge.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
import { useState, useEffect } from 'react';
let id = 0;
let hashId = 0;
const KEY = '$f';
function useMultipleFiltersId({
hash
}) {
const [fId] = useState(() => {
const _id = hash ? hashId : id;
const newFId = _id ? `${KEY}${_id}` : '';
hash ? hashId++ : id++;
return newFId;
});
useEffect(() => {
return () => {
hash ? hashId-- : id--;
};
}, []);
return fId;
}
function removeCacheIds(params) {
return Object.fromEntries(Object.entries(params).filter(([key]) => !key.startsWith(KEY)));
}
function filterByCacheIds(id, params) {
if (id) {
return params;
}
return Object.fromEntries(Object.entries(params).filter(([key]) => key.startsWith(KEY)));
}
export { filterByCacheIds, removeCacheIds, useMultipleFiltersId };
//# sourceMappingURL=useMultipleFiltersId.js.map