Skip to content

Instantly share code, notes, and snippets.

@nimish-gupta
Last active June 29, 2019 16:04
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/c5886b777f879e67ab7bd530e9ad2da2 to your computer and use it in GitHub Desktop.
Save nimish-gupta/c5886b777f879e67ab7bd530e9ad2da2 to your computer and use it in GitHub Desktop.
React componentWillUnMount Lifecycle implemented in Reason React hooks
[@react.component]
let make = () => {
let (counter, setCounter) = React.useState(() => 0);
React.useEffect(() => {
let clearTimeout = Js.Global.setTimeout(() => setCounter(_ => counter + 1), 500);
Some(Js.Global.clearTimeout(clearTimeout)) // This will be called when the component will be un-mounted
});
("Counter is updated " ++ 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