Created
May 3, 2021 16:23
-
-
Save ChaseH88/0b1eb3d39e3f9570ea72cd1c7ff9c4dd to your computer and use it in GitHub Desktop.
Memo Function for React
This file contains hidden or 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 { 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