This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type Props = { | |
children: React.ReactNode; | |
}; | |
function Show({ | |
when, | |
children, | |
}: Props & { | |
when?: boolean | null; | |
}): JSX.Element | null { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts an object into formatted URL query parameters. | |
* @param {Object} obj - The object to be converted into query parameters. | |
* @returns {string} A string containing the formatted query parameters. | |
*/ | |
export function objectToQueryParams(obj: { [key: string]: string | number | boolean }): string { | |
const queryParams: string[] = []; | |
for (const key in obj) { | |
if (obj.hasOwnProperty(key)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState } from 'react'; | |
export function isDevelopment() { | |
return process.env.NODE_ENV === 'development'; | |
} | |
const domain = `${isDevelopment() ? 'http' : 'https'}://${window.location.host}`; | |
const addPrefix = (key: string) => `some-prefix-${key}`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback } from 'react'; | |
import { useSearchParams } from 'react-router-dom'; | |
type Value = string | number; | |
type Query = { | |
key: string; | |
value?: Value; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
const handleNextStep = maxStep => currentStep => { | |
if (maxStep) { | |
if (currentStep < maxStep) return currentStep + 1; | |
return currentStep; | |
} | |
return currentStep + 1; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useState, useRef } from "react"; | |
function useOneClickOutside() { | |
const node = useRef(null); | |
const [open, setOpen] = useState(false); | |
const handleClickOutside = (e) => { | |
if (node.current.contains(e.target)) { | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const paginateArray = <T>(arr: T[] = [], size: number = 10): T[][] => | |
arr.reduce<T[][]>((acc, val, i) => { | |
const idx = Math.floor(i / size); | |
const page = acc[idx] || (acc[idx] = []); | |
page.push(val); | |
return acc; | |
}, []); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Update "current" list with "next" list values using some valid list key | |
* | |
* @param current "current" list | |
* @param next "next" list containing values to update into "current" list | |
* @param key used to map values to be updated | |
* @returns updated list | |
*/ | |
export function updateByListKey<T>(current: T[], next: T[], key: keyof T): T[] { | |
const listMap = new Map(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useCallback, useState } from 'react'; | |
import * as React from 'react'; | |
type Result = { | |
measureRef: (node: unknown) => void; | |
isIntersecting: boolean; | |
observer?: IntersectionObserver; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
export const paginateArray = (arr = [], size = 10) => | |
arr.reduce((acc, val, i) => { | |
const idx = Math.floor(i / size); | |
const page = acc[idx] || (acc[idx] = []); | |
page.push(val); | |
return acc; |
NewerOlder