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
import React, { useState, useEffect } from 'react'; | |
const ImageLoad = React.memo(({ src, placeholder, alt = "" }) => { | |
const [loading, setLoading] = useState(true); | |
const [currentSrc, updateSrc] = useState(placeholder); | |
useEffect(() => { | |
// start loading original image | |
const imageToLoad = new Image(); | |
imageToLoad.src = src; |
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
class Node { | |
constructor(data) { | |
this.data = data; | |
this.children = []; | |
} | |
add(data) { | |
this.children.push(new Node(data)); | |
} | |
remove(data) { | |
this.children = this.children.filter(child => child.data !== data); |
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
class Node { | |
constructor(data) { | |
this.data = data; | |
this.children = []; | |
} | |
add(data) { | |
this.children.push(new Node(data)); | |
} | |
remove(data) { | |
this.children = this.children.filter((child) => child.data !== data); |
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
class Node { | |
constructor(data) { | |
this.data = data; | |
this.children = []; | |
} | |
add(data) { | |
this.children.push(new Node(data)); | |
} | |
remove(data) { | |
this.children = this.children.filter(child => child.data !== data); |
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
class Node { | |
constructor(data) { | |
this.data = data; | |
this.children = []; | |
} | |
add(data) { | |
this.children.push(new Node(data)); | |
} | |
remove(data) { | |
this.children = this.children.filter(child => child.data !== data); |
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
const shallowCompare = (prev, next) => { | |
for (let key in next) { | |
if (next[key] !== prev[key]) return false; | |
} | |
return true; | |
}; | |
export function memo(Component, areEqual = shallowCompare) { | |
let prevProps = {}; | |
let prevResult = JSX.Element | undefined; | |
return (nextProps) => { |