Skip to content

Instantly share code, notes, and snippets.

View KobbyMmo's full-sized avatar

Obed Amoasi KobbyMmo

  • Ghana
View GitHub Profile
@KobbyMmo
KobbyMmo / Image.js
Last active April 14, 2023 12:58
Lazy Loading in React
import PropTypes from "prop-types";
import React from "react";
function Image({ src: ImageSrc, root, rootMargin, threshold, alt, ...props }) {
const [src, setSrc] = React.useState(false);
const imageRef = React.useRef(null);
const callback = React.useCallback((entries) => {
const [entry] = entries;
if (entry.isIntersecting) {
@KobbyMmo
KobbyMmo / MemoizedChildren.jsx
Last active January 30, 2022 05:56
Avoid Unnecessary renders in React
function Info({ radius }) {
<div>
<p>Radius:{radius}</p>
<p>Area:{(radius * radius * 22) / 7}</p>
</div>;
}
const MemoizedInfo = React.memo(Info);
function Circle({ radius, xCenter, yCenter }) {