reading-notes

Aloysious' Codefellows Reading Notes

View the Project on GitHub

Code 301 Reading Notes

Class 02

<== Previous Lesson Next Lesson ==>

<== Home 🏠

States and Props

React Docs - State and Lifecycle

Converting a Function to a Class

You can convert a function component like Clock to a class in five steps:

  1. Create an ES6 class, with the same name, that extends React.Component.
  2. Add a single empty method to it called render().
  3. Move the body of the function into the render() method.
  4. Replace props with this.props in the render() body.
  5. Delete the remaining empty function declaration.

Adding Lifecycle Methods to a Class

In applications with many components, it’s very important to free up resources taken by the components when they are destroyed.

Before you can access the files on a file system, you need to mount the file system. Mounting a file system attaches that file system to a directory (mount point) and makes it available to the system. The root ( / ) file system is always mounted. source

React Docs - handling events

For example, with plain HTML, to prevent the default link behavior of opening a new page, you can write:

<a href="#" onclick="console.log('The link was clicked.'); return false">
  Click me
</a>

In React this could instead be:

function ActionLink() {
---------------------------------------------
  function handleClick(e) {
    e.preventDefault();                         <=========   Function
    console.log('The link was clicked.');
  }
---------------------------------------------
  return (
---------------------------------------------
    <a href="#" onClick={handleClick}>           <=========   Return
---------------------------------------------
      Click me
    </a>
  );
}

React Docs - conditional rendering

Determining When to Re-Render in React

The main benefit of immutability is that it helps you build pure components in React. Immutable data can easily determine if changes have been made, which helps to determine when a component requires re-rendering.

React Tutorial through Developer Tools

Note:

In JavaScript classes, you need to always call super when defining the constructor of a subclass. All React component classes that have a constructor should start with a super(props) call.

Lifting state into a parent component is common when React components are refactore

React Bootstrat Documentation

Netlify

Reading

Bookmark/Skim

<== Home 🏠