Skip to content

Instantly share code, notes, and snippets.

@nimish-gupta
Last active June 29, 2019 17:29
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/df788e88468c77b69c95b98095f130f1 to your computer and use it in GitHub Desktop.
Save nimish-gupta/df788e88468c77b69c95b98095f130f1 to your computer and use it in GitHub Desktop.
React componentDidUpdate LifeCycle implemented in Reason React hooks
[@react.component]
let make = (~name, ~) => {
let (counter, setCounter) => React.useState(() => 0);
// This will allow the change of the state/props only if certain props are passed or changed to.
React.useEffect1(
() => {
if (name === "componentDidUpdate") {
setCounter(_ => counter + 1);
None
}
},
[|name|] // Here we are listing dependency on which component will be re-rendered.
);
(name ++ "is called " ++ counter -> string_of_int ++ " times.") -> React.string;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment