Week 14 - Session 1 - React (Bind Methods, Render Lifecycle)

blog image source
Following on from the previous sessions;
Intro to React
React (Class, Stateful Components, Event Handlers)

Bind Methods: One of the reasons to use React for development, is its popularity is that it relies heavily on all of the Javascript. On a basic level, it is taking a component’s state, a Javascript object, and using Javascript functions to manipulate that state. The page is then rendered to reflect those changes.

The value of `this` depends on how the function was called, not where or when it was defined. Also, it is not affected by scope, like a variable would be. This means, that whenever you pass a function down another function, this will not refer to the same value. There are at least five ways to handle this context in React:
  • Use React.createClass
  • Bind in Render
  • Use Arrow Function in Render
  • Bind in Constructor
  • Arrow Function in Class Property
React Render Lifecycle: React enables to create components by invoking the React.createClass() method which expects a render method and triggers a lifecycle that can be hooked into via a number of so-called lifecycle methods.

To get a clear idea of the lifecycle we will need to differentiate between the initial creation phase, where the component is created, and state and props changes triggered updates as well as the component unmounting phase.
  • Initialization - In this phase, the React component prepares for the upcoming tough journey, by setting up the initial states and default props.
  • Mounting - After preparing with basic needs, state and props, our React Component is ready to mount in the browser DOM. This phase gives hook methods for before and after mounting of components.
  • Updation - This phase starts when the react component has taken birth on the browser and grows by receiving new updates. The component can be updated by two ways, sending new props or updating the state.
  • Unmounting - In this phase, the component is not needed and the component will get unmounted from the DOM.

5 Approaches for Handling `this` - https://medium.freecodecamp.org/react-binding-patterns-5-approaches-for-handling-this-92c651b5af56
ReactJs component lifecycle methods - https://hackernoon.com/reactjs-component-lifecycle-methods-a-deep-dive-38275d9d13c0
Understanding the React Component Lifecycle - https://plnkr.co/edit/0cN0tu?p=preview)

Popular posts from this blog

Week 9 to 12 - Learning with MCR Codes

Week 8 - Session 1 - JavaScript in the Browser

Week 9 - Session 1 - The Internet, the Web, HTTP