Skip to content

Instantly share code, notes, and snippets.

View dmorenogogoleva's full-sized avatar
:electron:
=^_^=

Daria Moreno-Gogoleva dmorenogogoleva

:electron:
=^_^=
View GitHub Profile
@dmorenogogoleva
dmorenogogoleva / use-previous.ts
Last active April 26, 2021 08:20
use-previous typescript hook
export function usePrevious<T> (value: T): T | undefined {
const ref = useRef<T>()
useEffect(() => {
ref.current = value
}, [value])
return ref.current
}
@dmorenogogoleva
dmorenogogoleva / groupBy.ts
Created June 6, 2021 11:09
custom groupBy
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
}
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 = {
@dmorenogogoleva
dmorenogogoleva / js
Created February 21, 2024 16:24
jest-example
describe('some text', () => {
it('my test', () => {
const res = 2 +2
expect((res)).toBe(4)
})
});