Skip to content

Instantly share code, notes, and snippets.

@francismarcus
francismarcus / extract.md
Last active December 20, 2022 11:34
Extract from styleguide

Memoize

To prevent the re-creation of objects and functions on re-renders.

Move stuff out of render

Any variable declared within the scope of a component gets re-created on every render

Move as much as you can out of the render:

@francismarcus
francismarcus / MEMOIZE.md
Created March 21, 2022 17:07 — forked from mrousavy/MEMOIZE.md
Memoize!!! 💾 - a react (native) performance guide
In computing, memoization or memoisation
is an optimization technique used primarily
to speed up computer programs by storing
the results of expensive function calls and  
returning the cached result when the same
inputs occur again.                                         
                                                     — wikipedia
import React from 'react';
export default function deferComponent(C: React.ComponentType) {
return function DeferedComponent(props: any) {
const [render, setRender] = React.useState(false);
useIsomorphicLayoutEffect(() => {
window.requestAnimationFrame(() => {
window.requestAnimationFrame(() => setRender(true));
});
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;