Forked from louisrli/gist:c136857f6d6ca7d26df868a985bd86bc
Last active
September 23, 2020 17:03
-
-
Save Ammar-64/5d3d23b123ababd0980adfbebf4ef9b8 to your computer and use it in GitHub Desktop.
Discussion questions on React.useEffect()
This file contains hidden or 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
1. When does a React component re-render? | |
2. How can you replicate componentWillUnmount using useEffect ? | |
3. How can you replicate componentDidUpdate using useEffect ? | |
4. What does the React.useMemo hook do? |
fadime-ozdemir
commented
Sep 22, 2020
1- React renders whenever there is a change in the state or props
2-Return a callback in useEffect's callback argument and it will be called before unmounting.
3-useEffect is a very useful hook. It receives a callback function that executes when the component has mounted and every time it updates. So it works similarly to the old componentDidMount() and componentDidUpdate() methods for class components.
4-useMemo is a React hook that memorizes the output of a function. That is it. useMemo accepts two arguments: a function and a list of dependencies. useMemo will call the function and return its return value.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment