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 function usePrevious<T> (value: T): T | undefined { | |
const ref = useRef<T>() | |
useEffect(() => { | |
ref.current = value | |
}, [value]) | |
return ref.current | |
} |
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 function groupBy(collection: any[], iteratee: string) { | |
return collection.reduce((result, value) => { | |
if (!value.hasOwnProperty(iteratee)) return result | |
const key = value[iteratee] | |
if (!result || !result[key]) { | |
result[key] = [value] | |
return result | |
} |
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 function usePreviousPersistent<T extends unknown>(value: T) { | |
const ref = useRef<{ value: T; prev: T | null }>({ | |
value, | |
prev: null, | |
}); | |
const currentValue = ref.current.value; | |
if (!isEqual(value, currentValue)) { | |
ref.current = { |
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
describe('some text', () => { | |
it('my test', () => { | |
const res = 2 +2 | |
expect((res)).toBe(4) | |
}) | |
}); |