Notes – implementing componentWillReceiveProps and componentWillUnmount

In this examplewe are going to create a simple list of notes where, every 10 seconds, we will simulate that we receive an update from the service with new data, and with componentWillReceivePropswe will register the last time we got an update from the server:

  1. The componentWillReceiveProps method is called right before rendering. Like shouldComponentUpdate, it is called whenever new props are passed to the component, or the state has changed. In this example, we need to create fake data, but data normally needs to come from an actual service:
  export const notes1 = [    {      title: 'Note 1',      content: 'Content for Note 1'    },    {      title: 'Note 2',      content: 'Content for Note ...

Get React Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.