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
/* | |
* Usage: | |
* const sortedArray = arrayOfObjects.sort((a, b) => compareTwoObjectsByField(a, b, 'fieldName')); | |
*/ | |
export function compareTwoObjectsByField(a, b, field) { | |
if (a[field] < b[field]) { | |
return -1; | |
} else if (a[field] > b[field]) { | |
return 1; | |
} |
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
# get list of all branches, current one will be marked with the * character | |
git branch | |
# create new branch called branch_name | |
git branch branch_name | |
# switch to existing branch called branch_name | |
git checkout branch_name | |
# create and checkout to just created branch, called branch_name |
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 JSConfetti from 'js-confetti' | |
const jsConfetti = new JSConfetti() | |
jsConfetti.addConfetti() |
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 { useEffect, useRef, useState } from 'react' | |
function useThrottle<T>(value: T, interval = 500): T { | |
const [throttledValue, setThrottledValue] = useState<T>(value) | |
const lastExecuted = useRef<number>(Date.now()) | |
useEffect(() => { | |
if (Date.now() >= lastExecuted.current + interval) { | |
lastExecuted.current = Date.now() | |
setThrottledValue(value) |
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 React, { useEffect, useState } from 'react' | |
import { useThrottle } from './useThrottle' | |
export default function App() { | |
const [value, setValue] = useState('hello') | |
const throttledValue = useThrottle(value) | |
useEffect(() => console.log(`throttledValue changed: ${throttledValue}`), [ | |
throttledValue, |