const urlParams: string = config.params ? `?${new URLSearchParams(config.params).toString()}` : '';
const urlWithParams = url + urlParams;
const requestInit: RequestInit = {
method: method.toUpperCase(),
headers: config.headers,
body: config.body ? JSON.stringify(config.body) : undefined,
};
const response =
This file contains hidden or 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
| /** | |
| * A UI component that visually indicates the active Tailwind CSS breakpoint | |
| * on the screen. It shows a floating indicator in the bottom-right corner of the page, | |
| * displaying the current breakpoint based on the viewport width. | |
| * | |
| * This component is only rendered in development mode (`process.env.NODE_ENV !== 'production'`), | |
| * helping developers quickly identify the active breakpoint while building responsive layouts. | |
| * | |
| * It uses the following breakpoints based on the default Tailwind CSS configuration: | |
| * - XS (extra small) — `sm:hidden` |
https://www.basedash.com/blog/typescript-object-with-dynamic-keys
Constrained Dynamic Keys At times, you'd want to constrain the dynamic keys to a specific set of values, perhaps based on another array or tuple.
const validKeys = ['a', 'b', 'c'] as const;
type ValidKeysType = typeof validKeys[number];
This file contains hidden or 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 SingletonRouter, { Router } from 'next/router'; | |
| import { useEffect } from 'react'; | |
| const defaultConfirmationDialog = async (msg?: string) => window.confirm(msg); | |
| /** | |
| * Inspiration from: https://stackoverflow.com/a/70759912/2592233 | |
| */ | |
| export const useLeavePageConfirmation = ( | |
| shouldPreventLeaving: boolean, |
Built with D3js and Cartogram.js. Province and territory data obtained from the Government of Canada's Open Data Portal.
This file contains hidden or 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
| // JavaScript Version | |
| export const buildFirstMiddleLastList = (list) => { | |
| const { 0: first, [list.length - 1]: last, ...rest } = list; | |
| return { | |
| first: first, | |
| middle: Object.values(rest), | |
| last: list.length > 1 ? last : undefined, | |
| }; |
This file contains hidden or 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
| // JavaScript Version | |
| export const buildFirstMiddleLastList = (list) => { | |
| const { 0: first, [list.length - 1]: last, ...rest } = list; | |
| return [ | |
| first, | |
| Object.values(rest), | |
| list.length > 1 ? last : undefined | |
| ]; |
This file contains hidden or 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
| const arrayData = ['a', 'b', 'c', 'd', 'e']; |
This file contains hidden or 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
| const arrayData = ['a', 'b', 'c', 'd', 'e']; | |
| arrayData[0]; // First element is "a" | |
| arrayData[arrayData.length -1]; // Last element is "e" | |
| // Middle elements | |
| arrayData[1]; // "b" | |
| arrayData[2]; // "c" | |
| arrayData[3]; // "d" |
This file contains hidden or 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
| const arrayData = ['a', 'b', 'c', 'd', 'e']; | |
| const { 0: first, [arrayData.length - 1]: last, ...rest } = arrayData; |
NewerOlder