Book Image

React.js Essentials

By : Artemij Fedosejev
Book Image

React.js Essentials

By: Artemij Fedosejev

Overview of this book

Table of Contents (18 chapters)
React.js Essentials
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Understanding React component's lifecycle methods


Think about what a React component does. It describes what to render. We know that it uses the render() method for this. However, sometimes, having only the render() method is not enough because what if we want to do something before or after the component has rendered? What if we want to be able to decide whether a component's render() method should be called at all?

Looks like what we're describing is a process during which the React component is rendered. This process has various stages, for example, before render, render, after render, and so on. In React, this process is called the component's lifecycle. Each React component goes through this process. What we want is a way to hook into that process, and call our own functions at different stages of that process in order to have a greater control over it. For this purpose, React provides a number of methods that we can use to get notified when a certain stage in a component's lifecycle...