ProgrammingFarmer

Article Tag: React

React2025-02-11

Understanding the Top-Level Rule of React Hooks: Insights from React Hooks Source Code and Data Structures

The React official documentation clearly states "Only call Hooks at the top level," which extends to various rules when using Hooks, such as not using Hooks in if/else conditions or loops. But why can't we call Hooks in conditions, loops, or other situations? This is actually related to the data structure of React Hooks. This article will explore the reasons behind this rule by examining the React Hooks source code.

React2025-01-08

Understanding useEffect Hooks for Data Fetching and Subscriptions - Common Pitfalls and Solutions

React's useEffect Hook is essential for managing side effects, but its use for data fetching and subscriptions can lead to race conditions, memory leaks, and duplicate operations. This article explores common problems in useEffect for data fetching and subscriptions, and introduces practical solutions.

Redux, React2023-08-31

Understanding Redux Source Code (5) - From HOC to Hooks, Implementing useSelector and useDispatch

As React-Redux versions have evolved, the official recommendation has shifted toward using Hooks instead of the previous HOC pattern (e.g., `connect`). In this article, we'll explore the benefits of this transition and understand and implement React-Redux's most important Hooks - useSelector and useDispatch.

Redux, React2023-07-30

Understanding Redux Source Code (4) - Understanding React-Redux Combination Through Provider and connect

In the frontend world, it's uncommon to use Redux alone, but rather React and Redux together, aka React-Redux. In this article, we'll explore the implementation of the core parts of React-Redux, focusing mainly on the Provider component and connect method.

React2021-05-01

Deep Understanding of React.createElement and JSX

When writing React, we're accustomed to using JSX syntax, but after using it for a while, questions arise - What does JSX compile to? What's the underlying Raw API? What are JSX's features? We'll explore these questions in this article!