Last active
June 29, 2019 16:04
-
-
Save nimish-gupta/c5886b777f879e67ab7bd530e9ad2da2 to your computer and use it in GitHub Desktop.
React componentWillUnMount Lifecycle implemented in Reason React hooks
This file contains 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
[@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