Last active
June 29, 2019 17:29
-
-
Save nimish-gupta/df788e88468c77b69c95b98095f130f1 to your computer and use it in GitHub Desktop.
React componentDidUpdate 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 = (~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