In which lifecycle method should you make API calls in a class component?

  • componentDidMount
  • componentWillUnmount
  • render
  • constructor
You should make API calls in the componentDidMount lifecycle method of a class component. This method is called once after the component has been mounted in the DOM, making it suitable for actions like fetching data from an API. The other options (componentWillUnmount, render, and constructor) are not the appropriate places for making API calls.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *