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
function chunk(arr = [], size = 1) { | |
const compact = arr.slice(0, arr.length - (arr.length % size)); | |
const chunks = []; | |
for (let i = 0; i < compact.length/ size; i++) { | |
let start = i === 0 ? 0 : i * size; | |
let end = i === 0 ? size : i * size + size; | |
chunks.push(arr.slice(start, end)) | |
} | |
chunks.push(arr.slice(compact.length, arr.length)); | |
return chunks |
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, useRef, useState } from 'react'; | |
type GeoState = | |
| { | |
status: 'idle'; | |
} | |
| { | |
status: 'success'; | |
state: GeolocationPosition; | |
} |
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
// Used for flatten complex object type | |
type Flatten<T> = { | |
[K in keyof T]: T[K]; | |
}; | |
// Set K as required | |
type RequiredPick<T, K extends keyof T> = Flatten< | |
{ | |
[P in K]-?: T[P]; | |
} & Omit<T, K> |