Aloysious' Codefellows Reading Notes
<== Previous Lesson Next Lesson ==>
<== Home 🏠
You can convert a function component like Clock
to a class in five steps:
React.Component
.render()
.render()
method.props
with this.props
in the render()
body.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
false
to prevent default behavior in React.preventDefault
explicitly.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>
);
}
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.
render
method and don’t have their own state. Instead of defining a class which extends React.Component
, we can write a function that takes props
as input and returns what should be rendered. Function components are less tedious to write than classes, and many components can be expressed this way.Note:
In JavaScript classes, you need to always call
super
when defining the constructor of a subclass. All React component classes that have aconstructor
should start with asuper(props)
call.
Lifting state into a parent component is common when React components are refactore
<== Home 🏠