Initial commit from prod-batam

This commit is contained in:
mario
2025-05-27 10:51:12 +07:00
commit 025b96229b
3361 changed files with 304068 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
import useDebounce from './useDebounce.js';
import useSearchParams from './useSearchParams';
export { useDebounce, useSearchParams };

View File

@@ -0,0 +1,31 @@
import { useState, useEffect } from 'react';
/**
* See: https://usehooks.com/useDebounce/
*
* @param {*} value
* @param {number} delay - delat in ms
*/
export default function useDebounce(value, delay) {
// State and setters for debounced value
const [debouncedValue, setDebouncedValue] = useState(value);
useEffect(
() => {
// Update debounced value after delay
const handler = setTimeout(() => {
setDebouncedValue(value);
}, delay);
// Cancel the timeout if value changes (also on delay change or unmount)
// This is how we prevent debounced value from updating if value is changed ...
// .. within the delay period. Timeout gets cleared and restarted.
return () => {
clearTimeout(handler);
};
},
[value, delay] // Only re-call effect if value or delay changes
);
return debouncedValue;
}

View File

@@ -0,0 +1,24 @@
import { useLocation } from 'react-router';
/**
* It returns a URLSearchParams of the query parameters in the URL, where the keys are
* either lowercase or maintain their case based on the lowerCaseKeys parameter.
* @param {lowerCaseKeys:boolean} true to return lower case keys; false (default) to maintain casing;
* @returns {URLSearchParams}
*/
export default function useSearchParams(options = { lowerCaseKeys: false }) {
const { lowerCaseKeys } = options;
const searchParams = new URLSearchParams(useLocation().search);
if (!lowerCaseKeys) {
return searchParams;
}
const lowerCaseSearchParams = new URLSearchParams();
for (const [key, value] of searchParams) {
lowerCaseSearchParams.set(key.toLowerCase(), value);
}
return lowerCaseSearchParams;
}