Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Ammar-64/5d3d23b123ababd0980adfbebf4ef9b8 to your computer and use it in GitHub Desktop.
Save Ammar-64/5d3d23b123ababd0980adfbebf4ef9b8 to your computer and use it in GitHub Desktop.
Discussion questions on React.useEffect()
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
Copy link

answers

@Luey-A
Copy link

Luey-A commented Sep 23, 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