Skip to content

Instantly share code, notes, and snippets.

View DannyMichaels's full-sized avatar

Daniel Michael DannyMichaels

View GitHub Profile
@codemile
codemile / useSafeState.tsx
Created March 19, 2021 11:10
Here is a useSafeState hook that ignores state changes after a component has been unmounted.
import {
DependencyList,
Dispatch,
MutableRefObject,
SetStateAction,
useCallback,
useEffect,
useRef,
useState
} from 'react';
@kosalvann
kosalvann / max.js
Last active September 17, 2022 17:42
Define a function max() that takes two numbers as arguments and returns the largest of them. Use the if-then-else construct available in Javascript.
// Define a function max() that takes two numbers as
// arguments and returns the largest of them. Use the
// if-then-else construct available in Javascript.
// https://jsfiddle.net/ryjtyomv/
function max(firstNum, secondNum){
if (firstNum > secondNum) {
console.log(firstNum + " is larger than " + secondNum);
} else {