Skip to content

Instantly share code, notes, and snippets.

@ChaseH88
Created May 3, 2021 16:23
Show Gist options
  • Select an option

  • Save ChaseH88/0b1eb3d39e3f9570ea72cd1c7ff9c4dd to your computer and use it in GitHub Desktop.

Select an option

Save ChaseH88/0b1eb3d39e3f9570ea72cd1c7ff9c4dd to your computer and use it in GitHub Desktop.
Memo Function for React
import { memo as m, NamedExoticComponent } from "react";
import { isEqual } from "./lodash";
/**
* React memo utility function. Uses the Lodash 'isEqual' function to compare
* by default. You may also create and pass in your own compare function.
* @param component Your React Component
* @param areEqual Optional: Pass your own compare function.
* @example memo(<Component />, areEqual)
*/
const memo = (component: any, areEqual?: () => any): NamedExoticComponent => (
m(component, areEqual ? areEqual : isEqual)
);
export { memo };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment