Search By Label
// Custom Hook const useProducts = () => { const [products, setProducts] = useState([]); useEffect(() => { fetch("/api/products") .then((res) => res.json()) .then((data) => setProducts(data)); }, []); return products; }; // Container Component function ProductContainer() { const products = useProducts(); return <ProductList products={products} />; } // Presentational Component function ProductList({ products }) { return ( <ul> {products.map((product) => ( <li key={product.id}>{product.name}</li> ))} </ul> ); }
memo
lets you skip re-rendering a component when its props are unchanged.memo
to get a memoized version of that component. This memoized version of your component will usually not be re-rendered when its parent component is re-rendered as long as its props have not changed. But React may still re-render it: memoization is a performance optimization, not a guarantee.import { memo } from 'react';
const SomeComponent = memo(function SomeComponent(props) {
// ...
});