Skip to content

Instantly share code, notes, and snippets.

View Code-Victor's full-sized avatar
need more time!

Hamzat Victor Oluwabori Code-Victor

need more time!
View GitHub Profile
import { AnimatedView, Text, View } from '@/components/ui'
import { useMemo } from 'react'
const NUM_HOLDERS = 16
const NUM_BARS = 40
const rotateKeyframes = {
'0%': {
transform: [{ rotate: '0deg' }],
},

Frameworks like React require that when you change the contents of an array or object you change its reference. Or push another way that you don't change arrays but instead create new arrays with updated values (i.e. immutability).

There are older array methods that are incompatible with immutability because they alter the array in place and don't change the array reference. These are mutable (or destructive) methods.

Shown below are replacements for the array destructive methods (e.g. push, pop, splice, sort, etc.) that will create new array references with the updated data.

Solutions are provided using the spread operator and also the newer "change array by copy" methods (toSpliced, toSorted, toReversed and with).

Setting Value At Index

@mcraz
mcraz / Time Since JS
Created April 27, 2014 16:13
Get time difference in human readable format
function timeSince(date) {
var seconds = Math.floor((new Date() - date) / 1000);
var interval = Math.floor(seconds / 31536000);
if (interval > 1) {
return interval + " years";
}
interval = Math.floor(seconds / 2592000);