Skip to content

Instantly share code, notes, and snippets.

@nimish-gupta
Last active June 29, 2019 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nimish-gupta/32f9d4264dfb553e73b25b461a192332 to your computer and use it in GitHub Desktop.
Save nimish-gupta/32f9d4264dfb553e73b25b461a192332 to your computer and use it in GitHub Desktop.
React shouldComponent LifeCycle implemented in Reason React hooks
[@react.component]
let make = (~name) => name -> React.string;
// If you want to shallow compare the props then use React.memo
let make = React.memo(make);
// If you want to custom compare the nested props then use React.memoCustomCompareProps
let deepCompare = (nextProps, currentProps) => nextProps === currentProps;
let make = React.memoCustomCompareProps(
make,
(nextProps, currentProps) => {
let result = deepCompare(nextProps, currentProps);
result;
}
);
@nimish-gupta
Copy link
Author

If you getting error like This expression's type contains type variables that can't be generalized try to give your props types in the function definition like

let make = (~name: string) => name -> React.string;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment