React Flashcards
What does the constructor method do ?
This method is called when the component is first created, and is used to initialize state, bind event handlers, and perform other setup tasks.
Which React component phase includes the invoking of the constructor function ?
Mounting
getDerivedStateFromProps(props, state)
This method is called every time a component is re-rendered, and is used to update the component state based on changes to the props.
Which phase includes invoking of getDerivedStateFromProps(props, state)
Mounting and Updating
Which react component phase includes invoking of the render function ?
Mounting and Updating
Which react component phase includes invoking of the componentDidMount method ?
Mounting
purpose of the render method ?
This method is called every time a component needs to be rendered, and returns the JSX to be rendered to the DOM.
purpose of component did mount method ?
This method is called immediately after the component is inserted into the DOM, and is used to perform any setup tasks that require access to the DOM, such as initializing third-party libraries or setting up event listeners.
What happens in the Mounting Phase of a React component ?
Mounting phase: These methods are called when an instance of a component is being created and inserted into the DOM.
- constructor()
- getDerivedStateFromProps(props, state)
- render()
- componentDidMount()
purpose of shouldComponentUpdate(nextProps, nextState):
This method is called before a component is re-rendered, and can be used to prevent unnecessary re-renders by returning false.
purpose of getSnapshotBeforeUpdate(prevProps, prevState):?
This method is called immediately before a component is re-rendered, and can be used to capture some information from the DOM (such as scroll position) before it is updated.
purpose of componentDidUpdate(prevProps, prevState, snapshot) ?
This method is called immediately after a component is re-rendered, and is used to perform any necessary cleanup or additional setup tasks.
What happens in the Updating Phase ? Which methods are called / invoked ?
These methods are called when a component is being re-rendered due to changes in its props or state.
* getDerivedStateFromProps(props, state):
* shouldComponentUpdate(nextProps, nextState):
* render():
* getSnapshotBeforeUpdate(prevProps, prevState):
* componentDidUpdate(prevProps, prevState, snapshot):
purpose of componentWillUnmount() ?
This method is called just before a component is removed from the DOM, and is used to perform any necessary cleanup tasks, such as removing event listeners or canceling network requests.
What happens in the unmounting phase ?
Unmounting phase: This method is called when a component is being removed from the DOM.
—- componentWillUnmount()