Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Getting Started with React

You're reading from  Getting Started with React

Product type Book
Published in Apr 2016
Publisher
ISBN-13 9781783550579
Pages 212 pages
Edition 1st Edition
Languages
Authors (3):
Doel Sengupta Doel Sengupta
Profile icon Doel Sengupta
Manu Singhal Manu Singhal
Profile icon Manu Singhal
Danillo Corvalan Danillo Corvalan
Profile icon Danillo Corvalan
View More author details

Table of Contents (18) Chapters

Revisiting the code


In each of the React components (readingList and bookList), getInitialState() is initialized with the store public method getReadingList() and getLibrary(), respectively.

Various methods are executed at precise points in a component's lifecycle.

  • componentWillMount() is a React lifecycle method. It is invoked once, both on the client and server, immediately before the initial rendering occurs. If you call setState within this method, render() will see the updated state and will be executed only once despite change in the state:

    componentWillMount:function(){
        AppStore.addChangeListener(this._onChange)
      },
      _onChange: function(){
        this.setState(readingItems())
      }
  • Thus, componentWillMount() is listening to the addChangeListener (defined in the AppStore store). If the _onChange parameter is passed, then the current object (_this) is updated (setState) with the new/updated data/payload (readingItems).

  • In order to remove the items from the reading list, the event listener...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}